\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{array}
\usepackage{color}
\usepackage{graphicx}
\usepackage{float}
\PassOptionsToPackage{hyphens}{url}
\usepackage[hidelinks]{hyperref}
\usepackage{listings}
\usepackage[margin=1in]{geometry}
\usepackage{setspace}
\usepackage{natbib}
\usepackage{proof}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{wrapfig}
\usepackage [english]{babel}
\usepackage{grffile}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage[tikz]{bclogo}
\usetikzlibrary{chains}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usepackage{lscape}
\usepackage [autostyle, english = american]{csquotes}
\usepackage{enumitem}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{indentfirst}
\usepackage{hyperref}
\usepackage{pdfpages}
\usepackage{booktabs}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\bibliographystyle{apsr}
\bibpunct{(}{)}{;}{a}{,}{,}
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\setlength{\tabcolsep}{.18cm}
\usepackage{fancyvrb}
\usepackage{sectsty}
\sectionfont{\fontsize{14}{14}\selectfont}
\subsectionfont{\fontsize{12}{12}\selectfont}
\usepackage{numprint}
\npthousandsep{,}

\usepackage{listings}
\lstset{
basicstyle=\small\ttfamily,
columns=flexible,
breaklines=true
}

% COLOR CODING OUR COMMENTS
\newenvironment{bluetext}{\color{blue}}{\ignorespacesafterend} 

% ==Cross Referencing Different Docs
\usepackage{xr}
\externaldocument{ColombiaCOVID_Paper5}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title{{\LARGE When Pandemic Threat Does Not Stoke Xenophobia:\\
Evidence from a Panel Survey around COVID-19}\footnote{This research received institutional review board (IRB) approval from 
UCLA (\#19-001733) and UBC ($\#$H19-03288). % comment to anonymize
%XXX and YYY Universities. % uncomment for anonymized version
Our Pre-Analysis Plan (PAP) was archived in the OSF repository
\url{https://osf.io/kuwch}. % comment to anonymize
%\url{https://osf.io/pwvzq/download} (anonymized). % uncomment for anonymized version
%All replication material, including {\tt R} code and data, will be made available via Harvard University's Dataverse.
}
}

\author{Yang-Yang Zhou\thanks{Assistant Professor, Department of Government, Dartmouth College and CIFAR Fellow, \href{mailto:yang-yang.zhou@dartmouth.edu}{yang-yang.zhou@dartmouth.edu}, \href{https://www.yangyangzhou.com/}{www.yangyangzhou.com}}
\hspace{1.5cm}
Daniel Rojas\thanks{Ph.D. Candidate, Department of Political Science, University of British Columbia, \href{mailto:daniel.rojaslozano@ubc.ca}{daniel.rojaslozano@ubc.ca}}
\hspace{1.5cm}
Margaret Peters\thanks{Associate Professor, Department of Political Science, UCLA, \href{mailto:mepeters@ucla.edu}{mepeters@ucla.edu}, \href{http://www.maggiepeters.com/}{www.maggiepeters.com}}
}

\date{\today 
}
%%%%%%%%%%%%%%%%% END OF PREAMBLE %%%%%%%%%%%%%%%%


\begin{document}

<<eval=TRUE,echo=FALSE, results='hide', message=FALSE>>= 
library(knitr)

opts_chunk$set(cache = TRUE, 
        cache.path = 'cache_SI/',
        fig.path = 'figures_SI/', 
        tidy = TRUE, 
        echo = FALSE, 
        warning = FALSE, 
        message = FALSE, 
        fig.pos = 'H',
        dev = 'pdf', 
        dpi=200)

options(width = 110, digits = 1, scipen=10000)

@


\maketitle
\vspace{-2cm}


<<eval=TRUE, echo = FALSE, tidy=TRUE, warning=FALSE, error=FALSE, message=FALSE>>=

setwd("Paper_Inputs")

## Load data and functions
library(estimatr, quietly = TRUE)
library(foreign, quietly = TRUE)
library(ggplot2, quietly = TRUE)
library(tidyverse, quietly = TRUE)
library(reshape2, quietly = TRUE)
library(gtools, quietly = TRUE)
library(stringr, quietly = TRUE)
library(patchwork, quietly = TRUE)
library(knitr, quietly = TRUE)
library(kableExtra, quietly = TRUE)
library(CBPS, quietly = TRUE)
#library(sp, quietly = TRUE) #GIS packages
#library(spdep, quietly = TRUE)
#library(rgdal, quietly = TRUE)
#library(maps, quietly = TRUE)
#library(mapdata, quietly = TRUE)
#library(ggmap, quietly = TRUE)
library(lfe, quietly = TRUE)
library(foreach, quietly = TRUE)
library(data.table, quietly = TRUE)
library(equivtest, quietly = TRUE) # equivalence analysis
library(haven, quietly = TRUE)
library(survey, quietly = TRUE)
library(powerLATE, quietly = TRUE)
library(pwr, quietly = TRUE)
library(purrr, quietly = TRUE)


'%notin%' <- Negate('%in%')

## ggplot theme
yy_theme <- function(){
  theme(panel.background = element_blank(),
          legend.title = element_blank(), 
          plot.title = element_text(size = 10),
          panel.border = element_rect(colour = "gray70", fill=NA, size=.11),
          legend.position = "none",
          axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=11))
}

# load 2019 data
df_col <- read_csv("colombia_clean.csv")

df_col <- df_col %>% # rescale these variables to min 0 max 1 for observational regression analysis
 mutate(dir_contact_bi = case_when(dir_contact_index > 1~1, 
                  dir_contact_index <= 1~0,
                      TRUE~NA_real_),
     open_index_res = scales::rescale(open_index), 
     partisanship_res = scales::rescale(partisanship),
     skilled_labor_res = scales::rescale(skilled_labor),
     contract_res = scales::rescale(contract),
     salary_res = scales::rescale(salary),
     benefits_index_res = scales::rescale(benefits_index),
     dir_contact_index_res = scales::rescale(dir_contact_index),
     indir_contact_index_res = scales::rescale(indir_contact_index),
     cultural_index_res = scales::rescale(cultural_index)
     ) 

df_col_cali <- df_col[df_col$city == "Cali",]
df_col_cucuta <- df_col[df_col$city == "Cúcuta",]

# load 2021 panel data
col_wide <- read_csv("col_wide.csv") %>% mutate(open_index_4q_b = scales::rescale(open_index_4q_b), 
                                                # rescale openness to be between 0 and 1
                                                open_index_4q_e = scales::rescale(open_index_4q_e))

col_long <- read_csv("col_long.csv") %>% mutate(open_index_4q = scales::rescale(open_index_4q))

col_wide$recontacted <- 1
col_wide$recontacted2 <- "Recontacted"

col_long <- col_long %>%
  mutate(period = fct_relevel(period, "baseline", "endline"),
         period_x_treatment = (period == "endline") * covid_first,
         #city_num = case_when(city_num == 1~1, city_num == 2~0, TRUE~NA_real_),
         religion_cath = case_when(religion2 == 1~1, !is.na(religion2)~0, TRUE~NA_real_),
         religion_evan = case_when(religion2 == 2~1, !is.na(religion2)~0, TRUE~NA_real_),
         religion_other = case_when(religion2 == 3~1, !is.na(religion2)~0, TRUE~NA_real_),
         race_mestizo = case_when(race == 2~1, !is.na(race)~0, TRUE~NA_real_),
         cov_selffamily = case_when((cov_self == 1 | cov_family == 1)~1, 
                                   (cov_self == 0 & cov_family == 0)~0,
                                    TRUE~NA_real_),
         ven_friends_bi = case_when(ven_friends > 0~1, ven_friends == 0~0, TRUE~NA_real_),
         migQ_first = case_when(covid_first == 0~1, covid_first == 1~0,  TRUE~NA_real_),
         cov_natgov_bi = case_when(cov_natgov >= 3~1, cov_natgov <3~0, TRUE~NA_real_),
         cov_locgov_bi = case_when(cov_locgov >= 3~1, cov_locgov <3~0, TRUE~NA_real_)
  )

# attrited group
df_col_attrit <- df_col[which(toupper(df_col$name) %notin% col_wide$name),]
df_col_attrit$recontacted <- 0
df_col_attrit$recontacted2 <- "Attrited"

# load 2021 crossectional data
col_cross <- read_csv("col_cross.csv") %>% 
  mutate(open_index_4q = scales::rescale(open_index_4q), 
         city_num = case_when(city_num == 1~1, city_num == 2~0, TRUE~NA_real_),
         religion_cath = case_when(religion2 == 1~1, !is.na(religion2)~0, TRUE~NA_real_),
         religion_evan = case_when(religion2 == 2~1, !is.na(religion2)~0, TRUE~NA_real_),
         religion_other = case_when(religion2 == 3~1, !is.na(religion2)~0, TRUE~NA_real_),
         race_mestizo = case_when(race == 2~1, !is.na(race)~0, TRUE~NA_real_),
         kids = as.numeric(kids),
         city = case_when(city == "1"~"Cali", city == "2"~"Cúcuta", TRUE~city),
         cov_selffamily = case_when((cov_self == 1 | cov_family == 1)~1, 
                                   (cov_self == 0 & cov_family == 0)~0,
                                    TRUE~NA_real_),
         ven_friends_bi = case_when(ven_friends > 0~1, ven_friends == 0~0, TRUE~NA_real_),
         migQ_first = case_when(covid_first == 0~1, covid_first == 1~0,  TRUE~NA_real_),
         cov_natgov_bi = case_when(cov_natgov >= 3~1, cov_natgov <3~0, TRUE~NA_real_),
         cov_locgov_bi = case_when(cov_locgov >= 3~1, cov_locgov <3~0, TRUE~NA_real_)
         )

col_new <- col_cross[col_cross$panelist == 0,]

# Latinobarometer and LAPOP surveys
all_groups <- readRDS('all_groups.rds')
data_ipa <- readRDS('data_ipa.rds')
lb_col_20 <- readRDS('latinobarometer_col_20.rds')
lapop21_total <- readRDS('lapop_col_21.rds')
lapop21_a <- readRDS('lapop_col_21_a.rds')
lapop21_b <- readRDS('lapop_col_21_b.rds')

# LAPOP weights
lapop_weights <- read_csv("LAPOPweights.csv")
 
# 2019 survey data
colombia = read.csv('colombia_clean.csv') %>% 
    mutate(mestizo = ifelse(race==2,1,0),
           nationality = 'Colombians') 

venezuela = read.csv('venezuelans_clean.csv') %>% 
    mutate(mestizo = ifelse(race==2,1,0),
           nationality = 'Venezuelans') 

dt_race = rbind(colombia %>% dplyr::select(race, mestizo, city, nationality), 
           venezuela %>% dplyr::select(race, mestizo, city, nationality))


@

\pagenumbering{gobble}

%To number supplemental material with 'S': 
\renewcommand{\thesection}{S\arabic{section}}   
\renewcommand{\thetable}{S\arabic{table}}   
\renewcommand{\thefigure}{S\arabic{figure}}
\renewcommand{\theequation}{S\arabic{equation}}

\part*{\large For Online Publication: Supplementary Information}

\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\tableofcontents

\newpage
\pagenumbering{arabic}
\setcounter{page}{1}
\setstretch{1}

%\section{Additional Context}


\section{Descriptive Statistics}
\label{SIsec:demog}

This section summarizes the demographic covariates across groups: new (orange), panel (black), and all (blue) respondents. Moreover, it presents comparisons between Colombians and Venezuelans across races. Our respondents tend to be older (\Sexpr{sum(col_cross$age == 5, na.rm = T)/nrow(col_cross)*100}\% are 55+), \Sexpr{sum(col_cross$male == 0, na.rm = T)/nrow(col_cross)*100}\% identify as women, \Sexpr{sum(col_cross$race == 2, na.rm = T)/nrow(col_cross)*100}\% identify as Mestizo, and most have completed primary (\Sexpr{sum(col_cross$education == 1, na.rm = T)/nrow(col_cross)*100}\%) or secondary (\Sexpr{sum(col_cross$education == 2, na.rm = T)/nrow(col_cross)*100}\%) education. Most are in SEL strata 3 (\Sexpr{sum(col_cross$strata == 3, na.rm = T)/nrow(col_cross)*100}\%) or 4 (\Sexpr{sum(col_cross$strata == 4, na.rm = T)/nrow(col_cross)*100}\%), with on average \Sexpr{mean(col_cross$wealth_index, na.rm = T)} household items of the 14 we asked about (e.g. TV, stove, washing machine, etc.). While \Sexpr{sum(col_cross$employed == 1, na.rm = T)/nrow(col_cross)*100}\% are employed, of those, \Sexpr{(sum(col_cross$contract == 1, na.rm = T)/(table(is.na(col_cross$contract))[1]))*100}\% have informal contracts. Most identify politically as center (\Sexpr{sum(col_cross$partisanship == 2, na.rm = T)/nrow(col_cross)*100}\%) or right (\Sexpr{sum(col_cross$partisanship == 3, na.rm = T)/nrow(col_cross)*100}\%), and religiously as Catholic (\Sexpr{sum(col_cross$religion2 == 1, na.rm = T)/nrow(col_cross)*100}\%) and very religious (\Sexpr{sum(col_cross$religiosity == 3, na.rm = T)/nrow(col_cross)*100}\%). Because we stratified sampled our new respondents, demographically they are very similar to our panelists. 

<<demographics, eval = TRUE, echo = FALSE, tidy=TRUE, fig.pos = 'H', fig.width = 10, fig.height = 10, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="This figure shows demographic statistics across new (orange), panel (black), and all (blue) respondents.">>=

#All group
col_cross_all <- col_cross
col_cross_all$panelist <- 2
col_cross_all <- rbind(col_cross, col_cross_all)

age <- ggplot(col_cross_all[is.na(col_cross_all$age)==F,], 
              aes(x=as.character(age), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Age") +
  xlab("") +
  scale_y_continuous(limits = c(0,.6)) +
  scale_x_discrete(labels = c("18-24", 
                              "25-34",
                              "35-44",
                              "45-54",
                              "55+")) + 
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.title = element_blank(),
    legend.position = c(.2, .7)) + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))
  
male <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_male = mean(male, na.rm = T),
            se_male = sd(male, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$male, na.rm = T), 
          sd(col_cross$male, na.rm = T)/sqrt(sum(!is.na(col_cross$male))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_male, fill = panelist)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_male-1.96*se_male, 
                    ymax=mean_male+1.96*se_male), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,.6)) +
  ggtitle("Male") +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

race <- ggplot(col_cross_all[is.na(col_cross_all$race)==F,], 
               aes(x=as.character(race), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Race") +
  xlab("") +
  scale_y_continuous(limits = c(0,.6)) +
  scale_x_discrete(labels = c('Other',
                              'Whi',
                              'Mes',
                              'Ind',
                              'Afr',
                              'Mul')) + 
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

education <- ggplot(col_cross_all[is.na(col_cross_all$education)==F,], 
               aes(x=as.character(education), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Education") +
  xlab("") +
  scale_y_continuous(limits = c(0,.6)) +
  scale_x_discrete(labels = c('None',
                              'Pri',
                              'Sec',
                              'Tech',
                              'Univ',
                              'Grad')) + 
  ylab("Proportion") +
   theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

city <- ggplot(col_cross_all[is.na(col_cross_all$city)==F,], 
               aes(x=as.character(city), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("City") +
  xlab("") +
  scale_y_continuous(limits = c(0,.6)) +
  scale_x_discrete(labels = c('Cali', 'Cúcuta')) + 
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

strata <- ggplot(col_cross_all[is.na(col_cross_all$strata)==F,], 
               aes(x=as.character(strata), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Socioeconomic Strata") +
  scale_y_continuous(limits = c(0,.6)) +
  xlab("") +
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

kids <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_kids = mean(kids, na.rm = T),
            se_kids = sd(kids, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$kids, na.rm = T), 
          sd(col_cross$kids, na.rm = T)/sqrt(sum(!is.na(col_cross$kids))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_kids, fill = panelist)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_kids-1.96*se_kids, 
                    ymax=mean_kids+1.96*se_kids), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,2.5)) +
  ggtitle("Average No. of Children") +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

marriage <- ggplot(col_cross_all[is.na(col_cross_all$marriage)==F,], 
               aes(x=as.character(marriage), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Marriage") +
  xlab("") +
  scale_y_continuous(limits = c(0,.6)) +
  scale_x_discrete(labels = c('Single','Married','Divorced','Widow','Civil')) + 
  ylab("Proportion") +
   theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

partisanship <- ggplot(col_cross_all[is.na(col_cross_all$partisanship)==F,], 
               aes(x=as.character(partisanship), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Partisanship") +
  xlab("") +
  scale_x_discrete(labels = c('Left','Center','Right')) + 
  scale_y_continuous(limits = c(0,.6)) +
  ylab("Proportion") +
   theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

religion <- ggplot(col_cross_all[is.na(col_cross_all$religion2)==F,], 
               aes(x=as.character(religion2), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Religion") +
  scale_y_continuous(limits = c(0,.75)) +
  xlab("") +
  scale_x_discrete(labels = c('Catholic','Evangelical','Other')) + 
  ylab("Proportion") +
   theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

religiosity <- ggplot(col_cross_all[is.na(col_cross_all$religiosity)==F,], 
               aes(x=as.character(religiosity), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Religiosity") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  scale_x_discrete(labels = c('Not',
                              'Somewhat',
                              'Quite',
                              'Very')) + 
  ylab("Proportion") +
   theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

employed <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_employed = mean(employed, na.rm = T),
            se_employed = sd(employed, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$employed, na.rm = T), 
          sd(col_cross$employed, na.rm = T)/sqrt(sum(!is.na(col_cross$employed))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_employed, fill = panelist)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_employed-1.96*se_employed, 
                    ymax=mean_employed+1.96*se_employed), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,.6)) +
  ggtitle("Employed") +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

contract <- ggplot(col_cross_all[is.na(col_cross_all$contract)==F,], 
               aes(x=as.character(contract), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Labor Contract | Employed") +
  xlab("") +
  scale_y_continuous(limits = c(0,.75)) +
  scale_x_discrete(labels = c('Informal','Formal','Temp')) + 
  ylab("Proportion") +
   theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

salary <- ggplot(col_cross_all[is.na(col_cross_all$salary)==F,], 
               aes(x=as.character(salary), fill=as.character(panelist))) + 
  geom_bar(aes(y = ..prop.., group=panelist), position = "dodge") +
  ggtitle("Household Wages") +
  scale_y_continuous(limits = c(0,.6)) +
  xlab("") +
  scale_x_discrete(labels = c('Difficulties',
                              'Not enough',
                              'Enough',
                              'Can save')) + 
  ylab("Proportion") +
   theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

wealth <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_wealth_index = mean(wealth_index, na.rm = T),
            se_wealth_index = sd(wealth_index, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$wealth_index, na.rm = T), 
          sd(col_cross$wealth_index, na.rm = T)/sqrt(sum(!is.na(col_cross$wealth_index))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_wealth_index, fill = panelist)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_wealth_index-1.96*se_wealth_index, 
                    ymax=mean_wealth_index+1.96*se_wealth_index), 
                width = 0.2) +
  #scale_y_continuous(limits = c(0,.6)) +
  ggtitle("Wealth Index (14 items)") +
  xlab("") +
  ylab("Proportion") +
 theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

# plot
age + male + race + 
  education + city + strata + 
  kids + marriage + partisanship +
  plot_layout(ncol = 3)

@

<<demographics2, eval = TRUE, echo = FALSE, tidy=TRUE, fig.pos = 'H', fig.width = 10, fig.height = 7, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="This figure shows demographic statistics across new (orange), panel (black), and all (blue) respondents.">>=

religion + religiosity + employed +
  contract + salary + wealth + 
  plot_layout(ncol = 3)

@


\subsection{Comparing Racial Demographics among Colombians and Venezuelans from our surveys}
\label{SIsubsec:racialcompare}

Although the Colombian National Administrative Department of Statistics (DANE in Spanish) has surveyed Venezuelan migrants, it has not asked about race. Unfortunately, well-known surveys such as LAPOP or Latinobarometer do not have data for Venezuela either. For this reason, we compare race among Colombians and Venezuelans using original survey data from another research study we conducted in 2019 in the same two cities we study in this paper. In the 2019 project, we surveyed 1000 Colombians and 1600 Venezuelans. We sampled Colombians following a stratified sampling technique and Venezuelans using official registries with information about areas with a high density of Venezuelans. In such areas, we sampled Venezuelans following a random selection of blocks and a skip rule for units. We measured demographic characteristics, including self-reported race, in all respondents. Figure \ref{fig:racial_comparison} shows practically the same distribution of self-reported race by nationality.


<<racial_comparison, eval = TRUE, echo = FALSE, tidy=TRUE, fig.pos = 'H', fig.width = 10, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="This figure shows racial distribution across Colombians and Venezuelans from our 2019 surveys conducted in Cali and Cúcuta.">>=
    
dt_race %>% 
    ggplot(., aes(x=as.factor(race), fill=nationality)) +
    geom_bar(aes(y = ..prop.., group=nationality), position = 'dodge') +
    ggtitle("Self-reported Race") +
    scale_x_discrete(labels = c('White',
                                'Mestizo',
                                'Indig.',
                                'Afro',
                                'Mulato',
                                'Other')) +
    scale_y_continuous(limits = c(0,.6)) +
    xlab("") +
    ylab("") +
    theme(
        panel.background = element_blank(),
        panel.border = element_rect(colour = "gray", fill=NA, size=.8), 
        legend.position = c(.9,.8)) +
    scale_fill_manual(values = c("#D55E00","#0072B2"),
                      name="Nationality", labels=c("Colombians","Venezuelans")) #+
   # facet_grid(~city) 


@


\clearpage
\newpage
\subsection{Porportion of respondents who reported leaving their house in the past month}
\label{SIsubsec:lefthouse}

These plots show that within a month of our 2021 survey, only half of respondents went to work, to the doctor's, to take public transportation, go walk in a public park, and/or for a family member's or friend's house. Very few people went to school, a government office, or a restaurant. The most common place they went to if they left their house was to buy groceries (over 80\% of respondents). 

%%Did people leave their house in the past month?
<<covid_leavehouse, eval = TRUE, echo = FALSE, tidy=TRUE, fig.pos= 'H', fig.width = 11.5, fig.height = 8.5, out.width= "1\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="This figure shows the proportion of new (orange), panel (black), and all (blue) respondents who reported that they left their house in the past month for the following places. All estimates include 95\\% CIs.">>=

# Bar plots for health outcomes (covid questions) - Cross-section ####

## cov_leave_work
cov_leave_work <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_work = mean(cov_leave_work, na.rm = T),
            se_cov_leave_work = sd(cov_leave_work, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$cov_leave_work, na.rm = T), 
          sd(col_cross$cov_leave_work, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_work))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_work, fill = panelist)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_work-1.96*se_cov_leave_work, 
                    ymax=mean_cov_leave_work+1.96*se_cov_leave_work), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) +
  ggtitle("Work") +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.title = element_blank(),
    legend.position = c(.25, .8)) + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

## cov_leave_school
cov_leave_school <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_school = mean(cov_leave_school, na.rm = T),
            se_cov_leave_school = sd(cov_leave_school, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$cov_leave_school, na.rm = T), 
          sd(col_cross$cov_leave_school, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_school))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_school, fill = panelist)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_school-1.96*se_cov_leave_school, 
                    ymax=mean_cov_leave_school+1.96*se_cov_leave_school), 
                width = 0.2) +
  ggtitle("School") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  ylab("") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))


## cov_leave_stores
cov_leave_stores <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_stores = mean(cov_leave_stores, na.rm = T),
            se_cov_leave_stores = sd(cov_leave_stores, na.rm = T)/sqrt(length(panelist))) %>%
  rbind(c(2, mean(col_cross$cov_leave_stores, na.rm = T), 
          sd(col_cross$cov_leave_stores, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_stores))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_stores, fill = panelist)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_stores-1.96*se_cov_leave_stores, 
                    ymax=mean_cov_leave_stores+1.96*se_cov_leave_stores), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) +
  ggtitle("Stores") +
  xlab("") +
  ylab("") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

## cov_leave_clinic
cov_leave_clinic <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_clinic = mean(cov_leave_clinic, na.rm = T),
            se_cov_leave_clinic = sd(cov_leave_clinic, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$cov_leave_clinic, na.rm = T), 
          sd(col_cross$cov_leave_clinic, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_clinic))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_clinic, fill = panelist)) +
  geom_bar(stat = "identity")  +
  scale_y_continuous(limits = c(0,1)) +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_clinic-1.96*se_cov_leave_clinic, 
                    ymax=mean_cov_leave_clinic+1.96*se_cov_leave_clinic), 
                width = 0.2) +
  ggtitle("Health Clinic") +
  xlab("") +
  ylab("") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
   scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

## cov_leave_govt
cov_leave_govt <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_govt = mean(cov_leave_govt, na.rm = T),
            se_cov_leave_govt = sd(cov_leave_govt, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$cov_leave_govt, na.rm = T), 
          sd(col_cross$cov_leave_govt, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_govt))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_govt, fill = panelist)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_govt-1.96*se_cov_leave_govt, 
                    ymax=mean_cov_leave_govt+1.96*se_cov_leave_govt), 
                width = 0.2) +
  ggtitle("Govt Office") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

## cov_leave_outside
cov_leave_outside <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_outside = mean(cov_leave_outside, na.rm = T),
            se_cov_leave_outside = sd(cov_leave_outside, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$cov_leave_outside, na.rm = T), 
          sd(col_cross$cov_leave_outside, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_outside))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_outside, fill = panelist)) +
  scale_y_continuous(limits = c(0,1)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_outside-1.96*se_cov_leave_outside, 
                    ymax=mean_cov_leave_outside+1.96*se_cov_leave_outside),
                width = 0.2) +
  ggtitle("Public Park") +
  xlab("") +
  ylab("") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

# cov_leave_transp
cov_leave_transp <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_transp = mean(cov_leave_transp, na.rm = T),
            se_cov_leave_transp = sd(cov_leave_transp, na.rm = T)/sqrt(length(panelist))) %>% 
  rbind(c(2, mean(col_cross$cov_leave_transp, na.rm = T), 
          sd(col_cross$cov_leave_transp, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_transp))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_transp, fill = panelist)) +
  scale_y_continuous(limits = c(0,1)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_transp-1.96*se_cov_leave_transp, 
                    ymax=mean_cov_leave_transp+1.96*se_cov_leave_transp),
                width = 0.2) +
  ggtitle("Public\nTransportation") +
  xlab("") +
  ylab("") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

# cov_leave_rest
cov_leave_rest <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_rest = mean(cov_leave_rest, na.rm = T),
            se_cov_leave_rest = sd(cov_leave_rest, na.rm = T)/sqrt(length(panelist))) %>%
  rbind(c(2, mean(col_cross$cov_leave_rest, na.rm = T), 
          sd(col_cross$cov_leave_rest, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_rest))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_rest, fill = panelist)) +
  scale_y_continuous(limits = c(0,1)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_rest-1.96*se_cov_leave_rest, 
                    ymax=mean_cov_leave_rest+1.96*se_cov_leave_rest), 
                width = 0.2) +
  ggtitle("Restaurant") +
  xlab("") +
  ylab("") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))

# cov_leave_friends
cov_leave_friends <- col_cross %>%
  group_by(panelist=as.numeric(as.character(panelist))) %>%
  summarise(mean_cov_leave_friends = mean(cov_leave_friends, na.rm = T),
            se_cov_leave_friends = sd(cov_leave_friends, na.rm = T)/sqrt(length(panelist))) %>%
  rbind(c(2, mean(col_cross$cov_leave_friends, na.rm = T), 
          sd(col_cross$cov_leave_friends, na.rm = T)/sqrt(sum(!is.na(col_cross$cov_leave_friends))))) %>% 
  mutate(panelist = as.factor(panelist)) %>% 
  ggplot(., aes(x = panelist, y = mean_cov_leave_friends, fill = panelist)) +
  scale_y_continuous(limits = c(0,1)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=panelist, 
                    ymin=mean_cov_leave_friends-1.96*se_cov_leave_friends, 
                    ymax=mean_cov_leave_friends+1.96*se_cov_leave_friends), 
                width = 0.2) +
  ggtitle("Friends or\nFamily's House") +
  xlab("") +
  ylab("") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x=element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","gray20","#0072B2"),
                    name="Group", labels=c("New","Panel","All"))


# plot
cov_leave_work + cov_leave_school + cov_leave_stores + cov_leave_clinic + 
  cov_leave_govt + cov_leave_outside + cov_leave_transp + cov_leave_rest + 
  cov_leave_friends +
  plot_layout(ncol = 5)

@


\clearpage
\newpage
\section{Power Analysis}
\label{SIsec:power_analysis}

<<poweranalysis, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 7, fig.height = 4, out.width= "1\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, results='asis'>>=

n_seq <- seq(25, 500, by = 10)
sd_data <- .5
eff_detect <- purrr::map_dbl(n_seq, ~pwr.t.test(n = .x, sig.level = 0.05, power = .8)$d*sd_data)

pwr_df <- data.frame(n = n_seq, mde = eff_detect)

ggplot(pwr_df, aes(x = n*2, y = mde)) + 
  geom_line() + 
  geom_vline(aes(xintercept = 600), lty = "dashed") + 
  labs(x = "Study Sample Size\n(Balanced Treatment and Control Allocation)", 
       y = "Minimum Detectable Effect (Difference in Means)") + 
  theme_bw()

@

Our power analysis assumes a minimum statistical power of 0.8, an alpha of 0.05, and a standard deviation of .5. With a sample size of 600 (with equal treatment and control groups), we are able to detect an effect size of \Sexpr{pwr.t.test(n = 600/2, sig.level = 0.05, power = .8)$d*.5}. In comparison, our observed diff-in-diff effect size for the "Right to Seek Asylum" outcome was -.1, thus our study was well-powered to detect this effect for one of our main outcomes.


\section{Attrition and Equivalence Tests}
\label{SIsec:attrit}

In this section, we conduct equivalence tests between (1) the 2019 attrited respondents and panel respondents, and (2) panel respondents with the new respondents. The samples of attrited and panelist respondents are equivalent in age, the proportion of male, race (mestizo), religiosity, marital status, socioeconomic strata, and average wealth. Panelists and new respondents are equivalent in age, socioeconomic strata, religion, employment status, and wealth. p-values in tables \ref{table:equiv_0_1} and \ref{table:equiv_1_2} indicate whether we reject the null of nonequivalence (p-value < 0.05) between attrited and panelists, and panelists and new respondents, respectively.

<<equivalence, eval = TRUE, echo = FALSE, tidy=TRUE, warning=FALSE, message=FALSE, results='asis'>>=

# select balance covariates
variables = c('age18_44','age45_','male','white','mestizo','secondary_more_edu','city',
              'strata','kids','catholic','religious',
              'single','married','employed','rightist','informal','salary_enough',
              'wealth_index','open_index')
variable_df = c('Age (18-44)','Age (45 or +)','Percentage male','Race (White)',
                'Race (Mestizo)','Education (Secondary or more)',
                'City (Cali)','Strata','# Kids',
                'Catholic','Religious','Marital status (Single)',
                'Marital status (Married)',
                'Employed','Right vs Not','Informal Workers','Salary (enough)',
                'Wealth','Open Index')

all_groups[, (variables) := lapply(.SD, function(x) as.numeric(x)), .SDcols = variables]

# Attrited vs Recontacted
equiv_0_1 <- foreach(i = 1:length(variables), .combine = 'rbind') %do% {
  dt_0 = all_groups[group==0]
  dt_1 = all_groups[group==1]
  variable = variables[i] 
  # Observed mean difference
  diff_mean = (mean(dt_0[[variable]], na.rm = T) - mean(dt_1[[variable]], na.rm = T)) %>% 
    round(., 3)
  # Equivalence analysis
  eqv = equivtest::equiv.t.test(x = dt_0[[variable]], y = dt_1[[variable]],
                                eps_tol = 'strict')
  eqv_ci = eqv$CI_sub[2] %>% round(., 3)
  eqv_p = eqv$p %>% round(., 3)
  # return
  out = data.frame(Variable=variable_df[i], diff_mean,eqv_ci,eqv_p)
  return(out)
}

# Recontacted vs New respondents
equiv_1_2 <- foreach(i = 1:length(variables), .combine = 'rbind') %do% {
  dt_1 = all_groups[group==1]
  dt_2 = all_groups[group==2]
  variable = variables[i] 
  # Observed mean difference
  diff_mean = (mean(dt_1[[variable]], na.rm = T) - mean(dt_2[[variable]], na.rm = T)) %>% 
    round(., 3)
  # Equivalence analysis
  eqv = equivtest::equiv.t.test(x = dt_1[[variable]], y = dt_2[[variable]],
                                eps_tol = 'strict')
  eqv_ci = eqv$CI_sub[2] %>% round(., 3)
  eqv_p = eqv$p %>% round(., 3)
  # return
  out = data.frame(Variable=variable_df[i], diff_mean,eqv_ci,eqv_p)
  return(out)
}


knitr::kable(equiv_0_1, 'latex',
    caption = 'Equivalence Table - Attrited vs Panel \\label{table:equiv_0_1}',
             col.names =   c("Variable","Mean Difference",
                           "CI (+/-)",
                           "p-val"), position = 'h') %>%
  kable_styling(font_size = 7)

knitr::kable(equiv_1_2, "latex",
             caption = 'Equivalence Table - Panel vs New \\label{table:equiv_1_2}',
             col.names = c("Variable","Mean Difference",
                           "CI (+/-)",
                           "p-value"), position = 'h') %>%
  kable_styling(font_size = 7)

@



\clearpage
\newpage
\section{Demographic Comparison with National Surveys}
\label{SIsec:compare}

To alleviate concerns about sample size and representativeness, we compare our data with recent nationally representative data collected in Colombia by Innovations for Poverty Action (IPA), Latinobarometer, and LAPOP. IPA collected data between May and June 2020, Latinobarometer between November and December 2020, and LAPOP between March and May 2021. These datasets contain demographic data and information about respondents’ COVID-19 experiences. Latinobarometer and LAPOP also have data on attitudes toward migration. Although some questions are worded differently in our original survey, we summarize similar questions to put our findings in perspective. In general, our sample is similar to IPA, Latinobarometer, and LAPOP in most characteristics, including experiences during COVID, where we overlap. The only significant difference is that our sample is older.

Consistent with our results,  only 21.7\% of the Latinobarometer 2020 sample is open to receiving more Venezuelan migrants. Likewise, we find that 67.4\% of Latinobarometer respondents think that immigrants come to take their jobs. Although this latter question generally refers to immigrants, we observe a similar share of respondents in our sample thinking Venezuelans take Colombian jobs. In line with our results about the perceived benefit of Venezuelans' presence in Colombia, we find that 19.3\% of LAPOP respondents believe it is good for the Colombian economy that Venezuelans come to live in Colombia. We also see a similar share of respondents linking Venezuelans with security-related issues (80.3\% compared to 74.1\%). Thus, while we conducted our survey in two cities in Colombia, it mirrors national-level public opinion towards migrants. We also reweight the analyses using weights derived from LAPOP to create a nationally representative sample and find that our results are substantively unchanged (SI Section \ref{SIsec:weights}). 

<<comparing_data, eval=TRUE, echo = FALSE, warning=FALSE, error=FALSE, message=FALSE>>=

# plots national experiences with Covid 
combat_pandemic <- lb_col_20 %>%
  summarise(mean_ = mean(combat_pandemic_good, na.rm = T),
            se_ = sd(combat_pandemic_good, na.rm = T)/sqrt(length(na.omit(lb_col_20$combat_pandemic_good)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("The country has\na good capacity to\ncombat the pandemic") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

covid_main_problem <- lb_col_20 %>%
  summarise(mean_ = mean(covid_problem, na.rm = T),
            se_ = sd(covid_problem, na.rm = T)/sqrt(length(na.omit(lb_col_20$covid_problem)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,.5)) + 
  ggtitle("COVID-19 is the\nmost important problem\nin Colombia") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

fear_disease <- lb_col_20 %>%
  drop_na(fear_covid) %>%
  ggplot(., aes(x = fear_covid)) +
  geom_bar(aes(y = ..prop.., group=group),  fill = "#0072B2") +
  ggtitle('Fear of COVID-19') +
  xlab("") + ylab("") +
  scale_x_discrete(labels = c('Fearless','','','','','','','','','V. afraid')) +
  scale_y_continuous(limits = c(0,.5)) +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))


# Plots immigrant questions
receive_imm_ven <- lb_col_20 %>%
  summarise(mean_ = mean(acceptance_ven, na.rm = T),
            se_ = sd(acceptance_ven, na.rm = T)/sqrt(length(na.omit(lb_col_20$acceptance_ven)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("It is positive to receive\nVenezuelan migrants") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

impact_econ <- lb_col_20 %>%
  summarise(mean_ = mean(imm_economy_pos, na.rm = T),
            se_ = sd(imm_economy_pos, na.rm = T)/sqrt(length(na.omit(lb_col_20$imm_economy_pos)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2") +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Immigrants are good for\nour country's economy") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

imm_jobs <- lb_col_20 %>%
  summarise(mean_ = mean(imm_compete_jobs, na.rm = T),
            se_ = sd(imm_compete_jobs, na.rm = T)/sqrt(length(na.omit(lb_col_20$imm_compete_jobs)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Immigrants come to take our jobs") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

imm_crime <- lb_col_20 %>%
  summarise(mean_ = mean(imm_increase_crime, na.rm = T),
            se_ = sd(imm_increase_crime, na.rm = T)/sqrt(length(na.omit(lb_col_20$imm_increase_crime)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Immigrants increase crime rates") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

imm_society <- lb_col_20 %>%
  summarise(mean_ = mean(imm_improve_soc, na.rm = T),
            se_ = sd(imm_improve_soc, na.rm = T)/sqrt(length(na.omit(lb_col_20$imm_improve_soc)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Immigrants contribute with ideas to\nour culture and society") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

imm_burden_cnt <- lb_col_20 %>%
  summarise(mean_ = mean(imm_burden, na.rm = T),
            se_ = sd(imm_burden, na.rm = T)/sqrt(length(na.omit(lb_col_20$imm_burden)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Immigrants are a burden for the state") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

help_imm <- lb_col_20 %>%
  summarise(mean_ = mean(imm_help, na.rm = T),
            se_ = sd(imm_help, na.rm = T)/sqrt(length(na.omit(lb_col_20$imm_help)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Our country should help immigrants that\nsuffer political persecution in their countries") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

access_goods <- lb_col_20 %>%
  summarise(mean_ = mean(imm_access_goods, na.rm = T),
            se_ = sd(imm_access_goods, na.rm = T)/sqrt(length(na.omit(lb_col_20$imm_access_goods)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#0072B2")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Immigrants should have the same access\nto public goods as nationals") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))


# plots with covid experiences
covid_problem_lapop <- lapop21_total %>%
  summarise(mean_ = mean(covid_problem, na.rm = T),
            se_ = sd(covid_problem, na.rm = T)/sqrt(length(na.omit(lapop21_total$covid_problem)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#666633")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("COVID-19 is the most\nimportant problem in Colombia") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))


covid_concern_lapop <- lapop21_total %>%
  summarise(mean_ = mean(fear_covid_dummy, na.rm = T),
            se_ = sd(fear_covid_dummy, na.rm = T)/sqrt(length(na.omit(lapop21_total$fear_covid_dummy)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#666633")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Concern of COVID-19 contagion") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

cov_gov_lapop <- lapop21_a %>%
  summarise(mean_ = mean(correct_gov_measures, na.rm = T),
            se_ = sd(correct_gov_measures, na.rm = T)/sqrt(length(na.omit(lapop21_a$correct_gov_measures)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#666633")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("The national government has\nimplemented the right\nmeasures to contain COVID-19") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))


ind_econ_lapop <- lapop21_total %>%
  summarise(mean_ = mean(worse_ind_economy, na.rm = T),
            se_ = sd(worse_ind_economy, na.rm = T)/sqrt(length(na.omit(lapop21_total$worse_ind_economy)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#666633")  +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Economic situation is worse than\na year ago because of COVID-19") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))



## plots imm data
ven_services_lapop <- lapop21_b %>%
  summarise(mean_ = mean(ven_services, na.rm = T),
            se_ = sd(ven_services, na.rm = T)/sqrt(length(na.omit(lapop21_b$ven_services)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#666633") +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Government provides social\nservices to Venezuelans") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))


ven_sec_lapop <- lapop21_b %>%
  summarise(mean_ = mean(ven_increase_insec, na.rm = T),
            se_ = sd(ven_increase_insec, na.rm = T)/sqrt(length(na.omit(lapop21_b$ven_increase_insec)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#666633") +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Venezuelans worsen\ninsecurity problems") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))


ven_econ_lapop <- lapop21_b %>%
  summarise(mean_ = mean(ven_economy_pos, na.rm = T),
            se_ = sd(ven_economy_pos, na.rm = T)/sqrt(length(na.omit(lapop21_b$ven_economy_pos)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#666633") +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("It is good for the\nColombian economy that\nVenezuelans come to live here") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

ven_cult_lapop <- lapop21_b %>%
  summarise(mean_ = mean(ven_culture_pos, na.rm = T),
            se_ = sd(ven_culture_pos, na.rm = T)/sqrt(length(na.omit(lapop21_b$ven_culture_pos)))) %>% 
  ggplot(., aes(x = "", y = mean_)) +
  geom_bar(stat = "identity", fill = "#666633") +
  geom_errorbar(aes(ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) + 
  ggtitle("Venezuelans in Colombia enrich\nColombian culture") +
  xlab("") + ylab("") + 
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8))

# plots comparing demographics
age_lb <- all_groups %>% filter(., group_merge !=6 & group_merge!=7 
                      & group_merge != 0) %>%  
  drop_na(age) %>%
  ggplot(., aes(x=age, fill=group_merge)) + 
  geom_bar(aes(y = ..prop.., group=group_merge), position = "dodge") +
  ggtitle("Age") +
  xlab("") +
  scale_y_continuous(limits = c(0,1)) +
  scale_x_discrete(labels = c("18-24", 
                              "25-34",
                              "35-44",
                              "45-54",
                              "55+")) + 
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = c(.1, .8)) + 
  scale_fill_manual(values = c("#D55E00","black","#0072B2", "#666633"),
                    name="", labels=c("Our Respondents","IPA","Latinobarometer",
                                           "LAPOP"))

male_lb <- all_groups %>% filter(., group_merge !=6 & group_merge!=7 
                                 & group_merge != 0) %>% 
  group_by(group_merge) %>%
  summarise(mean_male = mean(male, na.rm = T),
            se_male = sd(male, na.rm = T)/sqrt(length(group_merge))) %>% 
  ggplot(., aes(x = group_merge, y = mean_male, fill = group_merge)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=group_merge, 
                    ymin=mean_male-1.96*se_male, 
                    ymax=mean_male+1.96*se_male), 
                width = 0.2) +
  scale_y_continuous(limits = c(0,1)) +
  ggtitle("Proportion of Males") +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","black","#0072B2", "#666633"))

race_lb <- all_groups %>% filter(., group_merge!=3 & group_merge !=6 
                                 & group_merge!=7 & group_merge != 0) %>% 
  drop_na(race) %>%
  ggplot(., aes(x=race, fill=group_merge)) + 
  geom_bar(aes(y = ..prop.., group=group_merge), position = "dodge") +
  ggtitle("Race") +
  xlab("") +
  scale_y_continuous(limits = c(0,1)) +
  scale_x_discrete(labels = c('Other','White','Mestizo','Indigenous',
                              'Afro','Mulato')) + 
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","#0072B2","#666633"))

religion_lb <-all_groups %>% filter(., 
                      group_merge!=3 & group_merge!=5 & 
                        group_merge!=6 & group_merge!=7
                      & group_merge != 0) %>%
  drop_na(religion2) %>%
  ggplot(., aes(x=religion2, fill=group_merge)) + 
  geom_bar(aes(y = ..prop.., group=group_merge), position = "dodge") +
  ggtitle("Religion") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  scale_x_discrete(labels = c('Catholic','Evangelical','Other')) + 
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","#0072B2"))

employed_lb <- all_groups %>% 
  filter(., group_merge!=3 & group_merge!=5 & group_merge!=6 & group_merge != 0) %>% 
  group_by(group_merge) %>%
  summarise(mean_employed = mean(employed, na.rm = T),
            se_employed = sd(employed, na.rm = T)/sqrt(length(group_merge))) %>% 
  drop_na(mean_employed) %>%
  ggplot(., aes(x = group_merge, y = mean_employed, fill = group_merge)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=group_merge, 
                    ymin=mean_employed-1.96*se_employed, 
                    ymax=mean_employed+1.96*se_employed), 
                width = 0.2) +
  ggtitle("Proportion with Employment") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","#0072B2","#666633"))

partisanship_lb <- all_groups %>% 
  filter(., group_merge!=3 & group_merge!=5 
         & group_merge!=7
         & group_merge != 0) %>% 
    drop_na(partisanship) %>%
  ggplot(., aes(x=partisanship, fill=group_merge)) + 
  geom_bar(aes(y = ..prop.., group=group_merge), position = "dodge") +
  ggtitle("Partisanship") +
  xlab("") +
  scale_x_discrete(labels = c('Left','Center','Right')) + 
  scale_y_continuous(limits = c(0,1)) +
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","#0072B2","#666633"))

marriage_lb <- all_groups %>% 
  filter(., group_merge !=3 & group_merge!=4 
         & group_merge!=5 & group_merge!=6
         & group_merge!=0) %>% 
      drop_na(marriage) %>%
  ggplot(., aes(x=marriage, fill=group_merge)) + 
  geom_bar(aes(y = ..prop.., group=group_merge), position = "dodge") +
  ggtitle("Marriage") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  scale_x_discrete(labels = c('Single','Married','Divorced','Widow',
                              'Civil Union')) + 
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","#666633"))

education <- all_groups %>%
  filter(., group_merge!=4 & group_merge!=5 & group_merge!=6 & group_merge!=7 
         & group_merge!=0) %>% 
  drop_na(education) %>%
  ggplot(., aes(x=education, fill=group_merge)) + 
  geom_bar(aes(y = ..prop.., group=group_merge), position = "dodge") +
  ggtitle("Education") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  scale_x_discrete(labels = c('None','Primary','High Sch.','Tech.',
                              'University', 'Master/PhD')) + 
  ylab("Proportion") +
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = "none") + 
  scale_fill_manual(values = c("#D55E00","black"))
  

# Comparing COVID-19 experience
data_ipa[, group_merge := case_when(groups=='0'|groups=='1'~'1',
                                    groups=='IPA 1st Round'~ '2',
                                    groups=='2'~'3',
                                    TRUE ~ NA_character_) %>% as.factor(.)]


gov_subsidy <- data_ipa %>% 
  group_by(group_merge) %>%
  summarise(mean_cov_assistance = mean(cov_assistance2, na.rm = T),
            se_cov_assistance = sd(cov_assistance2, na.rm = T)/sqrt(length(group_merge))) %>% 
  ggplot(., aes(x = group_merge, y = mean_cov_assistance, fill = group_merge)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=group_merge, 
                    ymin=mean_cov_assistance-1.96*se_cov_assistance, 
                    ymax=mean_cov_assistance+1.96*se_cov_assistance), 
                width = 0.2) +
  ggtitle("Received government\nassistance\nsince the pandemic began") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = c(.1, .8)) + 
  scale_fill_manual(values = c("#D55E00","black","#0072B2"),
                    name="", labels=c("Our Respondents",
                                           "IPA","Latinobarometer"))

cov_moving <- data_ipa %>% 
  filter(., group_merge!='3') %>% 
  group_by(group_merge) %>%
  summarise(mean_ = mean(cov_move, na.rm = T),
            se_ = sd(cov_move, na.rm = T)/sqrt(length(group_merge))) %>% 
  ggplot(., aes(x = group_merge, y = mean_, fill = group_merge)) +
  geom_bar(stat = "identity")  +
  geom_errorbar(aes(x=group_merge, 
                    ymin=mean_-1.96*se_, 
                    ymax=mean_+1.96*se_), 
                width = 0.2) +
  ggtitle("Living in same place\nas before the quarantine") +
  scale_y_continuous(limits = c(0,1)) +
  xlab("") +
  ylab("Proportion") +
  theme(
    axis.text.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    legend.position = 'none') + 
  scale_fill_manual(values = c("#D55E00","black"))

@

<<comparisons_covid plots, eval=TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 3.5, out.width= ".8\\linewidth", fig.show ='hold', fig.align='center', warning=FALSE, message=FALSE, fig.cap='This figure compares COVID-19 experience across our respondents (orange), IPA (black), and Latinobarometer (blue) respondents.'>>=

gov_subsidy + cov_moving +  
  plot_layout(ncol = 2, guides = "collect") 

@

<<comparisons_dem plots, eval=TRUE, echo = FALSE, tidy=TRUE, fig.width = 10, fig.height = 9, fig.show ='hold', fig.align='center', warning=FALSE, message=FALSE, fig.cap='This figure shows demographic statistics across our respondents (orange), IPA (black), Latinobarometer (blue), and LAPOP (green) respondents.'>>=

age_lb + male_lb + race_lb + 
  education + religion_lb + employed_lb +
  partisanship_lb + marriage_lb + guide_area() +
  plot_layout(ncol = 3, guides = "collect") 


@




\newpage
\subsection{Latinobarometer 2020}

<<latinobarometer_covid_exp plots, eval=TRUE, echo = FALSE, tidy=TRUE, fig.width = 10, fig.height = 3.5, fig.show ='hold', out.width="1\\linewidth", fig.align='center', warning=FALSE, message=FALSE, fig.cap='This figure shows experiences with COVID-19 in Latinobarometer respondents.'>>=

covid_main_problem + fear_disease + combat_pandemic +
  plot_layout(ncol = 3, guides = "collect") 

@

<<latinobarometer_imm plots, eval=TRUE, echo = FALSE, tidy=TRUE, fig.width = 11, fig.height = 9, fig.show ='hold', out.width="1\\linewidth", fig.align='center', warning=FALSE, message=FALSE, fig.cap='This figure shows perceptions toward immigrants in Latinobarometer respondents.'>>=

receive_imm_ven + impact_econ + imm_jobs + 
  imm_crime + imm_society + imm_burden_cnt + 
  help_imm + access_goods + plot_layout(ncol = 3, guides = 'collect') 

@

\newpage
\subsection{LAPOP 2021}

<<lapop_covid_exp plots, eval=TRUE, echo = FALSE, tidy=TRUE, fig.width = 13, fig.height = 4, fig.show ='hold', fig.align='center', out.width="1\\linewidth", warning=FALSE, message=FALSE, fig.cap='This figure shows experiences with COVID-19 in LAPOP respondents'>>=

covid_problem_lapop + covid_concern_lapop + cov_gov_lapop + ind_econ_lapop +
  plot_layout(ncol = 4, guides = "collect") 

@

<<lapop_imm plots, eval=TRUE, echo = FALSE, tidy=TRUE, fig.width = 13, fig.height = 4, fig.show ='hold', fig.align='center', out.width="1\\linewidth", warning=FALSE, message=FALSE, fig.cap='This figure shows perceptions toward immigrants in LAPOP respondents.'>>=

ven_services_lapop + ven_sec_lapop + ven_econ_lapop + ven_cult_lapop +
  plot_layout(ncol = 4, guides = "collect") 

@


\clearpage
\newpage
\section{Main Effects using LAPOP Weights}
\label{SIsec:weights}

In this section, we compare our sample and results to three nationally representative surveys: the 2020 IPA survey conducted between May and June, the 2020 Latinobarometer survey conducted between November and December, and the 2021 LAPOP survey conducted between March and May. Although many questions are worded differently in our original survey, we summarize similar questions to put our findings in perspective (SI Section \ref{SIsec:compare}). In general, our sample is similar to IPA, Latinobarometer, and LAPOP in most characteristics, including experiences during COVID, where we overlap. The only significant difference is that our sample is older.

Consistent with our results,  only 21.7\% of the Latinobarometer 2020 sample is open to receiving more Venezuelan migrants. Likewise, we find that 67.4\% of Latinobarometer respondents think that immigrants come to take their jobs. Although this latter question generally refers to immigrants, we observe a similar share of respondents in our sample thinking Venezuelans take Colombian jobs. In line with our results about the perceived benefit of Venezuelans' presence in Colombia, we find that 19.3\% of LAPOP respondents believe it is good for the Colombian economy that Venezuelans come to live in Colombia. We also see a similar share of respondents linking Venezuelans with security-related issues (80.3\% compared to 74.1\%). Thus, while we conducted our survey in two cities in Colombia, it mirrors national-level public opinion towards migrants. 

Finally, we use LAPOP to generate sets of weights for each of our main datasets -- the panel of 2019/2021 respondents, cross-sectional of all 2021 respondents which includes the endline for the panel as well as the new respondents, and for just the new 2021 respondents. We then reweight all of the main analyses shown in the paper using these nationally representative weights in order to address concerns about external validity for our sample. Results are substantively unchanged. 

<<gen_weights, eval = TRUE, echo = FALSE, tidy=TRUE>>=

# Format the weights
lapop_weights <- lapop_weights %>%
  mutate(
    variable = case_when(
      variable == "gender-male"~"gender_male",
      variable == "gender-female"~"gender_female",
      TRUE~variable
    ),
    variable = str_split(variable, pattern = "_"),
    value = map_chr(variable, 2),
    variable = map_chr(variable, 1)
  )

targets <- list(
  data.frame(gender_wt = lapop_weights$value[lapop_weights$variable == "gender"],
             Freq = lapop_weights$proportion[lapop_weights$variable == "gender"]),
  data.frame(strata_wt = lapop_weights$value[lapop_weights$variable == "strata"],
             Freq = lapop_weights$proportion[lapop_weights$variable == "strata"]),
  data.frame(age_wt = lapop_weights$value[lapop_weights$variable == "age"],
             Freq = lapop_weights$proportion[lapop_weights$variable == "age"]),
  data.frame(race_wt = lapop_weights$value[lapop_weights$variable == "race"],
             Freq = lapop_weights$proportion[lapop_weights$variable == "race"])
)

# Weight col_long
col_long_wt <- col_long %>%
  mutate(gender_wt = if_else(male == 1, 'male', 'female'),
         strata_wt = as.character(strata),
         age_wt = as.character(age),
         race_wt = case_when(
           race == 1~"white",
           race == 2~"mestizo",
           race == 3~"indigenous",
           race == 4~"afro",
           race == 5~"mulato",
           TRUE~"other"
         )) %>%
  drop_na(gender_wt, strata_wt, age_wt, race_wt) %>%
  dplyr::select(name, gender_wt, strata_wt, age_wt, race_wt) %>%
  distinct()
  
col_long_svydesign <- svydesign(~1, data = col_long_wt)
col_long_rake_out <- rake(
  col_long_svydesign, 
  sample.margins = list(~gender_wt, ~strata_wt, ~age_wt, ~race_wt), 
  population.margins = targets
)
col_long_wt$weight <- weights(col_long_rake_out)

col_long_wt <- col_long %>%
  left_join(col_long_wt %>% dplyr::select(name, weight))

# Weight col_cross
col_cross_wt <- col_cross %>%
  mutate(gender_wt = if_else(male == 1, 'male', 'female'),
         strata_wt = as.character(strata),
         age_wt = as.character(age),
         race_wt = case_when(
           race == 1~"white",
           race == 2~"mestizo",
           race == 3~"indigenous",
           race == 4~"afro",
           race == 5~"mulato",
           TRUE~"other"
         )) %>%
  drop_na(gender_wt, strata_wt, age_wt, race_wt)

col_cross_svydesign <- svydesign(~1, data = col_cross_wt)
col_cross_rake_out <- rake(
  col_cross_svydesign,
  sample.margins = list(~gender_wt, ~strata_wt, ~age_wt, ~race_wt),
  population.margins = targets
)
col_cross_wt$weight <- weights(col_cross_rake_out)

# Weight col_new
col_new_wt <- col_new %>% 
  mutate(gender_wt = if_else(male == 1, 'male', 'female'),
         strata_wt = as.character(strata),
         age_wt = as.character(age),
         race_wt = case_when(
           race == 1~"white",
           race == 2~"mestizo",
           race == 3~"indigenous",
           race == 4~"afro",
           race == 5~"mulato",
           TRUE~"other"
         )) %>%
  drop_na(gender_wt, strata_wt, age_wt, race_wt)

col_new_svydesign <- svydesign(~1, data = col_new_wt)
col_new_rake_out <- rake(
  col_new_svydesign,
  sample.margins = list(~gender_wt, ~strata_wt, ~age_wt, ~race_wt),
  population.margins = targets
)
col_new_wt$weight <- weights(col_new_rake_out)
@

<<mig_cov_results_wt, eval = TRUE, echo = FALSE, tidy=TRUE, fig.pos = 'H', fig.width = 10, fig.height = 6, out.width= "1\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="This figure shows questions about Venezuelan migrants and COVID asked at endline. The top plot shows the proportion of new (orange), panel (black), and all (blue) respondents who agreed with the statement. The bottom plot shows the treatment effect of COVID-First. All estimates include 95\\% CIs.">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long_wt %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), covid_first, weight) %>%
    mutate(survey_group = "Panel Respondents"),
  col_new_wt %>%
    dplyr::select(!!c(outcomes_cs, controls), covid_first, weight) %>%
    mutate(survey_group = "New Respondents",
           kids = as.numeric(kids)),
  col_cross_wt %>%
    dplyr::select(!!c(outcomes_cs, controls), covid_first, weight) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  dplyr::select(survey_group, !!outcomes_cs, weight) %>%
  pivot_longer(cols = -c(survey_group, weight), names_to = "outcome_var") %>%
  group_by(survey_group, outcome_var) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, survey_group, weight) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = ., weights = weight) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
) %>%
  mutate(survey_group = as.factor(survey_group),
         survey_group = fct_relevel(survey_group, "New Respondents", "Panel Respondents", "All Respondents"))

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = survey_group, colour = survey_group)) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#D55E00", "black", "#0072B2"), name = "Group", labels = c("New", "Panel", "All")) + 
  theme(
    axis.ticks.x=element_blank(),
    axis.title.x = element_blank(),
    panel.background = element_blank(),
    panel.border = element_rect(colour = "gray", fill=NA, size=.8),
    axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
    legend.position = "none")


@

<<mig_gen_did_wt, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 10.5, fig.height = 9, out.width= ".95\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="For each set of outcomes, the top plot shows over time means by COVID-First treatment (orange) vs. control (blue). The bottom plot shows the pre-post estimate and the Diff-in-Diff estimate of COVID-First interacted with period. All estimates include 95\\% CIs.">>=

##### PLOT 1
outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Estimate over-time means ##
overtime_means <- col_long_wt %>%
  dplyr::select(!!outcomes, period, weight) %>%
  pivot_longer(-c(weight, period), names_to = "outcome_var",
               values_to = "value") %>%
  group_by(outcome_var, period) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "Overall")

treatmentstatus_means <- col_long_wt %>%
  dplyr::select(!!outcomes, period, covid_first, weight) %>%
  pivot_longer(-c(period, covid_first, weight), 
               names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, period, covid_first) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "By Treatment Status")

mean_plot_df <- bind_rows(overtime_means, treatmentstatus_means)

#plot 
plot_overtime <- ggplot(treatmentstatus_means, aes(period, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  geom_line(position = position_dodge(.4), lty = "dashed") + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of\nRespondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("MIGRATION OPENNESS ATTITUDES")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_overtime1 <- plot_overtime + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## Regression analysis ##

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

controls <- paste0(controls, collapse = "+")

## Formula
form_main <- paste0("%s ~ period + ", controls, "| 0 | 0 | name")
form_did <- paste0("%s ~ period_x_treatment + ", controls, "| covid_first + period | 0 | name")

## --------
## Estimate
## --------
covid_did_out1 <- foreach(i = 1:length(outcomes), .combine = "rbind") %do% {
  
  ## Format formulas
  outcome <- outcomes[i]
  form_main_out <- sprintf(form_main, outcome)
  form_did_out <- sprintf(form_did, outcome)
  
  ## Regressions
  reg_main <- felm(as.formula(form_main_out), col_long_wt, weights = col_long_wt$weight)
  reg_did <- felm(as.formula(form_did_out), col_long_wt, weights = col_long_wt$weight)
  
  ## Tidy and return
  out <- bind_rows(
    tidy(reg_main, conf.int = TRUE) %>% filter(term == "periodendline") %>% mutate(outcome = outcome, model = "prepost_diff"),
    tidy(reg_did, conf.int = TRUE) %>% filter(term == "period_x_treatment") %>% mutate(outcome = outcome, model = "diff_in-diff")
  )
  
  return(out)
  
}

#plot 
plot_didresults1 <- ggplot(covid_did_out1,
                            aes(x = reorder(term, -desc(term)), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Treatment", 
       y = "Average Treatment Effects") +
  scale_x_discrete(labels=c("COVID-First x\nEndline", "Endline")) +
  coord_flip() +
  yy_theme() +
  theme(strip.text = element_blank())


##### PLOT 2
outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Estimate over-time means ##
overtime_means <- col_long_wt %>%
  dplyr::select(!!outcomes, period, weight) %>%
  pivot_longer(-c(weight, period), names_to = "outcome_var",
               values_to = "value") %>%
  group_by(outcome_var, period) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "Overall")

treatmentstatus_means <- col_long_wt %>%
  dplyr::select(!!outcomes, period, covid_first, weight) %>%
  pivot_longer(-c(period, covid_first, weight), 
               names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, period, covid_first) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "By Treatment Status")

mean_plot_df <- bind_rows(overtime_means, treatmentstatus_means)

#plot 
plot_overtime <- ggplot(treatmentstatus_means, aes(period, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  geom_line(position = position_dodge(.4), lty = "dashed") + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of\nRespondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("WHETHER MIGRANTS COMPETE FOR EMPLOYMENT")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_overtime2 <- plot_overtime + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .4, label = label)
)

## Regression analysis ##

## --------
## Estimate
## --------
covid_did_out2 <- foreach(i = 1:length(outcomes), .combine = "rbind") %do% {
  
  ## Format formulas
  outcome <- outcomes[i]
  form_main_out <- sprintf(form_main, outcome)
  form_did_out <- sprintf(form_did, outcome)
  
  ## Regressions
  reg_main <- felm(as.formula(form_main_out), col_long_wt, weights = col_long_wt$weight)
  reg_did <- felm(as.formula(form_did_out), col_long_wt, weights = col_long_wt$weight)
  
  ## Tidy and return
  out <- bind_rows(
    tidy(reg_main, conf.int = TRUE) %>% filter(term == "periodendline") %>% mutate(outcome = outcome, model = "prepost_diff"),
    tidy(reg_did, conf.int = TRUE) %>% filter(term == "period_x_treatment") %>% mutate(outcome = outcome, model = "diff_in-diff")
  )
  
  return(out)
  
}

#plot 
plot_didresults2 <- ggplot(covid_did_out2,
                            aes(x = reorder(term, -desc(term)), y = estimate)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray30") + 
  facet_wrap(~outcome, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Treatment", 
       y = "Average Treatment Effects") +
  scale_x_discrete(labels=c("COVID-First x\nEndline", "Endline")) +
  coord_flip() +
  yy_theme()  +
  theme(strip.text = element_blank())


##### Plot 3
outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Estimate over-time means ##
overtime_means <- col_long_wt %>%
  dplyr::select(!!outcomes, period, weight) %>%
  pivot_longer(-c(weight, period), names_to = "outcome_var",
               values_to = "value") %>%
  group_by(outcome_var, period) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "Overall")

treatmentstatus_means <- col_long_wt %>%
  dplyr::select(!!outcomes, period, covid_first, weight) %>%
  pivot_longer(-c(period, covid_first, weight), 
               names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, period, covid_first) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "By Treatment Status")

mean_plot_df <- bind_rows(overtime_means, treatmentstatus_means)

#plot 
plot_overtime <- ggplot(treatmentstatus_means, aes(period, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  geom_line(position = position_dodge(.4), lty = "dashed") + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of\nRespondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("WHETHER MIGRANTS BRING BENEFITS")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_overtime3 <- plot_overtime + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## Regression analysis ##

## --------
## Estimate
## --------
covid_did_out3 <- foreach(i = 1:length(outcomes), .combine = "rbind") %do% {
  
  ## Format formulas
  outcome <- outcomes[i]
  form_main_out <- sprintf(form_main, outcome)
  form_did_out <- sprintf(form_did, outcome)
  
  ## Regressions
  reg_main <- felm(as.formula(form_main_out), col_long_wt, weights = col_long_wt$weight)
  reg_did <- felm(as.formula(form_did_out), col_long_wt, weights = col_long_wt$weight)
  
  ## Tidy and return
  out <- bind_rows(
    tidy(reg_main, conf.int = TRUE) %>% filter(term == "periodendline") %>% mutate(outcome = outcome, model = "prepost_diff"),
    tidy(reg_did, conf.int = TRUE) %>% filter(term == "period_x_treatment") %>% mutate(outcome = outcome, model = "diff_in-diff")
  )
  
  return(out)
  
}

#plot 
plot_didresults3 <- ggplot(covid_did_out3,
                            aes(x = reorder(term, -desc(term)), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Treatment", 
       y = "Average Treatment Effects") +
  scale_x_discrete(labels=c("COVID-First x\nEndline", "Endline")) +
  coord_flip() +
  yy_theme()  +
  theme(strip.text = element_blank())


##### PLOT 4
outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Estimate over-time means ##
overtime_means <- col_long_wt %>%
  dplyr::select(!!outcomes, period, weight) %>%
  pivot_longer(-c(weight, period), names_to = "outcome_var",
               values_to = "value") %>%
  group_by(outcome_var, period) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "Overall")

treatmentstatus_means <- col_long_wt %>%
  dplyr::select(!!outcomes, period, covid_first, weight) %>%
  pivot_longer(-c(period, covid_first, weight), 
               names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, period, covid_first) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "By Treatment Status")

mean_plot_df <- bind_rows(overtime_means, treatmentstatus_means)

#plot 
plot_overtime <- ggplot(treatmentstatus_means, aes(period, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  geom_line(position = position_dodge(.4), lty = "dashed") + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of\nRespondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("WHETHER MIGRANTS CAN INTEGRATE")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_overtime4 <- plot_overtime + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## Regression analysis ##

## --------
## Estimate
## --------
covid_did_out4 <- foreach(i = 1:length(outcomes), .combine = "rbind") %do% {
  
  ## Format formulas
  outcome <- outcomes[i]
  form_main_out <- sprintf(form_main, outcome)
  form_did_out <- sprintf(form_did, outcome)
  
  ## Regressions
  reg_main <- felm(as.formula(form_main_out), col_long_wt, weights = col_long_wt$weight)
  reg_did <- felm(as.formula(form_did_out), col_long_wt, weights = col_long_wt$weight)
  
  ## Tidy and return
  out <- bind_rows(
    tidy(reg_main, conf.int = TRUE) %>% filter(term == "periodendline") %>% mutate(outcome = outcome, model = "prepost_diff"),
    tidy(reg_did, conf.int = TRUE) %>% filter(term == "period_x_treatment") %>% mutate(outcome = outcome, model = "diff_in-diff")
  )
  
  return(out)
  
}

#plot 
plot_didresults4 <- ggplot(covid_did_out4,
                            aes(x = reorder(term, -desc(term)), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Treatment", 
       y = "Average Treatment Effects") +
  scale_x_discrete(labels=c("COVID-First x\nEndline", "Endline")) +
  coord_flip() +
  yy_theme()  +
  theme(strip.text = element_blank())


##### PLOTS TOGETHER

(plot_overtime1 / plot_didresults1 / 
    plot_overtime2 / plot_didresults2) +
  plot_layout(heights = c(1, 1, 1, 1))


@

<<mig_gen_cs_wt, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 10.5, fig.height = 9, out.width= ".95\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="For each set of outcomes, the top plot shows endline means by COVID-First treatment (orange) vs. control (blue) across all, new, and panel respondents. The bottom plot shows the treatment effect of COVID-First by group. All estimates include 95\\% CIs.">>=

##### PLOT 1
outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long_wt %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new_wt %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross_wt %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, covid_first, survey_group) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(survey_group, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme() +
  ggtitle("MIGRATION OPENNESS ATTITUDES")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus1 <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out1 <- col_endline %>%
  dplyr::select(!!c(outcomes, controls), covid_first, survey_group, weight) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = ., weights = weight) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  
#plot 
plot_regresults1 <- ggplot(reg_out1, aes(x = survey_group, y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Survey Group", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme() +
  theme(strip.text = element_blank())

##### PLOT 2
outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long_wt %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new_wt %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross_wt %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, covid_first, survey_group) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(survey_group, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of Respondents") + 
  scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus2 <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out2 <- col_endline %>%
  dplyr::select(!!c(outcomes, controls), covid_first, survey_group, weight) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = ., weights = weight) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults2 <- ggplot(reg_out2, aes(x = survey_group, y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Survey Group", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme() +
  theme(strip.text = element_blank())

##### PLOT 3
outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long_wt %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new_wt %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross_wt %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, covid_first, survey_group) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(survey_group, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of Respondents") + 
  scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("MIGRANTS BRING BENEFITS")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus3 <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out3 <- col_endline %>%
  dplyr::select(!!c(outcomes, controls), covid_first, survey_group, weight) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = ., weights = weight) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults3 <- ggplot(reg_out3, aes(x = survey_group, y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Survey Group", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme() +
  theme(strip.text = element_blank())

##### PLOT 4
outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long_wt %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new_wt %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross_wt %>%
    dplyr::select(!!c(outcomes, controls), covid_first, weight) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, covid_first, survey_group) %>%
  do({
    lm_robust(value~1, data = ., weights = weight) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(survey_group, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme() +
  ggtitle("MIGRANTS CAN INTEGRATE")


dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus4 <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
) 

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out4 <- col_endline %>%
  dplyr::select(!!c(outcomes, controls), covid_first, survey_group, weight) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = ., weights = weight) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults4 <- ggplot(reg_out4, aes(x = survey_group, y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Survey Group", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme() +
  theme(strip.text = element_blank())

##### PLOT TOGETHER
(plot_treatmentstatus1 / plot_regresults1 / 
    plot_treatmentstatus2 / plot_regresults2) +
  plot_layout(heights = c(1, 1, 1, 1))

@

\clearpage
\newpage
\section{Additional Results}
\label{SIsec:full}

This section shows additional results for two additional groups of outcomes -- whether migrants bring benefits, and whether migrants can integrate. The two figures below mirror Figures 3 and 4 in the paper. 

<<mig_gen_did2, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 10, fig.height = 9, out.width= ".95\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="For each set of outcomes, the top plot shows over time means by COVID-First treatment (orange) vs. control (blue). The bottom plot shows the pre-post estimate and the Diff-in-Diff estimate of COVID-First interacted with period. All estimates include 95\\% CIs.">>=

##### PLOT 1
outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Estimate over-time means ##
overtime_means <- col_long %>%
  dplyr::select(!!outcomes, period) %>%
  pivot_longer(-period, names_to = "outcome_var",
               values_to = "value") %>%
  group_by(outcome_var, period) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Overall")

treatmentstatus_means <- col_long %>%
  dplyr::select(!!outcomes, period, covid_first) %>%
  pivot_longer(-c(period, covid_first), 
               names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, period, covid_first) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "By Treatment Status")

mean_plot_df <- bind_rows(overtime_means, treatmentstatus_means)

#plot 
plot_overtime <- ggplot(treatmentstatus_means, aes(period, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  geom_line(position = position_dodge(.4), lty = "dashed") + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of\nRespondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("MIGRATION OPENNESS ATTITUDES")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_overtime1 <- plot_overtime + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## Regression analysis ##

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

controls <- paste0(controls, collapse = "+")

## Formula
form_main <- paste0("%s ~ period + ", controls, "| 0 | 0 | name")
form_did <- paste0("%s ~ period_x_treatment + ", controls, "| covid_first + period | 0 | name")

## --------
## Estimate
## --------
covid_did_out1 <- foreach(i = 1:length(outcomes), .combine = "rbind") %do% {
  
  ## Format formulas
  outcome <- outcomes[i]
  form_main_out <- sprintf(form_main, outcome)
  form_did_out <- sprintf(form_did, outcome)
  
  ## Regressions
  reg_main <- felm(as.formula(form_main_out), col_long)
  reg_did <- felm(as.formula(form_did_out), col_long)
  
  ## Tidy and return
  out <- bind_rows(
    tidy(reg_main, conf.int = TRUE) %>% filter(term == "periodendline") %>% mutate(outcome = outcome, model = "prepost_diff"),
    tidy(reg_did, conf.int = TRUE) %>% filter(term == "period_x_treatment") %>% mutate(outcome = outcome, model = "diff_in-diff")
  )
  
  return(out)
  
}

#plot 
plot_didresults1 <- ggplot(covid_did_out1,
                            aes(x = reorder(term, -desc(term)), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Treatment", 
       y = "Average Treatment Effects") +
  scale_x_discrete(labels=c("COVID-First x\nEndline", "Endline")) +
  coord_flip() +
  yy_theme() +
  theme(strip.text = element_blank())


##### PLOT 2
outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Estimate over-time means ##
overtime_means <- col_long %>%
  dplyr::select(!!outcomes, period) %>%
  pivot_longer(-period, names_to = "outcome_var",
               values_to = "value") %>%
  group_by(outcome_var, period) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Overall")

treatmentstatus_means <- col_long %>%
  dplyr::select(!!outcomes, period, covid_first) %>%
  pivot_longer(-c(period, covid_first), 
               names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, period, covid_first) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "By Treatment Status")

mean_plot_df <- bind_rows(overtime_means, treatmentstatus_means)

#plot 
plot_overtime <- ggplot(treatmentstatus_means, aes(period, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  geom_line(position = position_dodge(.4), lty = "dashed") + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of\nRespondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("WHETHER MIGRANTS COMPETE FOR EMPLOYMENT")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_overtime2 <- plot_overtime + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .4, label = label)
)

## Regression analysis ##

## --------
## Estimate
## --------
covid_did_out2 <- foreach(i = 1:length(outcomes), .combine = "rbind") %do% {
  
  ## Format formulas
  outcome <- outcomes[i]
  form_main_out <- sprintf(form_main, outcome)
  form_did_out <- sprintf(form_did, outcome)
  
  ## Regressions
  reg_main <- felm(as.formula(form_main_out), col_long)
  reg_did <- felm(as.formula(form_did_out), col_long)
  
  ## Tidy and return
  out <- bind_rows(
    tidy(reg_main, conf.int = TRUE) %>% filter(term == "periodendline") %>% mutate(outcome = outcome, model = "prepost_diff"),
    tidy(reg_did, conf.int = TRUE) %>% filter(term == "period_x_treatment") %>% mutate(outcome = outcome, model = "diff_in-diff")
  )
  
  return(out)
  
}

#plot 
plot_didresults2 <- ggplot(covid_did_out2,
                            aes(x = reorder(term, -desc(term)), y = estimate)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray30") + 
  facet_wrap(~outcome, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Treatment", 
       y = "Average Treatment Effects") +
  scale_x_discrete(labels=c("COVID-First x\nEndline", "Endline")) +
  coord_flip() +
  yy_theme()  +
  theme(strip.text = element_blank())


##### Plot 3
outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Estimate over-time means ##
overtime_means <- col_long %>%
  dplyr::select(!!outcomes, period) %>%
  pivot_longer(-period, names_to = "outcome_var",
               values_to = "value") %>%
  group_by(outcome_var, period) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Overall")

treatmentstatus_means <- col_long %>%
  dplyr::select(!!outcomes, period, covid_first) %>%
  pivot_longer(-c(period, covid_first), 
               names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, period, covid_first) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "By Treatment Status")

mean_plot_df <- bind_rows(overtime_means, treatmentstatus_means)

#plot 
plot_overtime <- ggplot(treatmentstatus_means, aes(period, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  geom_line(position = position_dodge(.4), lty = "dashed") + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of\nRespondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("WHETHER MIGRANTS BRING BENEFITS")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_overtime3 <- plot_overtime + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## Regression analysis ##

## --------
## Estimate
## --------
covid_did_out3 <- foreach(i = 1:length(outcomes), .combine = "rbind") %do% {
  
  ## Format formulas
  outcome <- outcomes[i]
  form_main_out <- sprintf(form_main, outcome)
  form_did_out <- sprintf(form_did, outcome)
  
  ## Regressions
  reg_main <- felm(as.formula(form_main_out), col_long)
  reg_did <- felm(as.formula(form_did_out), col_long)
  
  ## Tidy and return
  out <- bind_rows(
    tidy(reg_main, conf.int = TRUE) %>% filter(term == "periodendline") %>% mutate(outcome = outcome, model = "prepost_diff"),
    tidy(reg_did, conf.int = TRUE) %>% filter(term == "period_x_treatment") %>% mutate(outcome = outcome, model = "diff_in-diff")
  )
  
  return(out)
  
}

#plot 
plot_didresults3 <- ggplot(covid_did_out3,
                            aes(x = reorder(term, -desc(term)), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Treatment", 
       y = "Average Treatment Effects") +
  scale_x_discrete(labels=c("COVID-First x\nEndline", "Endline")) +
  coord_flip() +
  yy_theme()  +
  theme(strip.text = element_blank())


##### PLOT 4
outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Estimate over-time means ##
overtime_means <- col_long %>%
  dplyr::select(!!outcomes, period) %>%
  pivot_longer(-period, names_to = "outcome_var",
               values_to = "value") %>%
  group_by(outcome_var, period) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Overall")

treatmentstatus_means <- col_long %>%
  dplyr::select(!!outcomes, period, covid_first) %>%
  pivot_longer(-c(period, covid_first), 
               names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, period, covid_first) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "By Treatment Status")

mean_plot_df <- bind_rows(overtime_means, treatmentstatus_means)

#plot 
plot_overtime <- ggplot(treatmentstatus_means, aes(period, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  geom_line(position = position_dodge(.4), lty = "dashed") + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of\nRespondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("WHETHER MIGRANTS CAN INTEGRATE")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_overtime4 <- plot_overtime + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## Regression analysis ##

## --------
## Estimate
## --------
covid_did_out4 <- foreach(i = 1:length(outcomes), .combine = "rbind") %do% {
  
  ## Format formulas
  outcome <- outcomes[i]
  form_main_out <- sprintf(form_main, outcome)
  form_did_out <- sprintf(form_did, outcome)
  
  ## Regressions
  reg_main <- felm(as.formula(form_main_out), col_long)
  reg_did <- felm(as.formula(form_did_out), col_long)
  
  ## Tidy and return
  out <- bind_rows(
    tidy(reg_main, conf.int = TRUE) %>% filter(term == "periodendline") %>% mutate(outcome = outcome, model = "prepost_diff"),
    tidy(reg_did, conf.int = TRUE) %>% filter(term == "period_x_treatment") %>% mutate(outcome = outcome, model = "diff_in-diff")
  )
  
  return(out)
  
}

#plot 
plot_didresults4 <- ggplot(covid_did_out4,
                            aes(x = reorder(term, -desc(term)), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Treatment", 
       y = "Average Treatment Effects") +
  scale_x_discrete(labels=c("COVID-First x\nEndline", "Endline")) +
  coord_flip() +
  yy_theme()  +
  theme(strip.text = element_blank())


##### PLOTS TOGETHER

(plot_overtime3 / plot_didresults3 / 
    plot_overtime4 / plot_didresults4) +
  plot_layout(heights = c(1, 1, 1, 1))


@

<<mig_gen_cs2, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 10, fig.height = 9, out.width= ".95\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="For each set of outcomes, the top plot shows endline means by COVID-First treatment (orange) vs. control (blue) across all, new, and panel respondents. The bottom plot shows the treatment effect of COVID-First by group. All estimates include 95\\% CIs.">>=

##### PLOT 1
outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, covid_first, survey_group) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(survey_group, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme() +
  ggtitle("MIGRATION OPENNESS ATTITUDES")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus1 <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out1 <- col_endline %>%
  dplyr::select(!!c(outcomes, controls), covid_first, survey_group) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  
#plot 
plot_regresults1 <- ggplot(reg_out1, aes(x = survey_group, y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Survey Group", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme() +
  theme(strip.text = element_blank())

##### PLOT 2
outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, covid_first, survey_group) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(survey_group, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of Respondents") + 
  scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus2 <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out2 <- col_endline %>%
  dplyr::select(!!c(outcomes, controls), covid_first, survey_group) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults2 <- ggplot(reg_out2, aes(x = survey_group, y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Survey Group", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme() +
  theme(strip.text = element_blank())

##### PLOT 3
outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, covid_first, survey_group) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(survey_group, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of Respondents") + 
  scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  ggtitle("MIGRANTS BRING BENEFITS")

dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus3 <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out3 <- col_endline %>%
  dplyr::select(!!c(outcomes, controls), covid_first, survey_group) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults3 <- ggplot(reg_out3, aes(x = survey_group, y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Survey Group", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme() +
  theme(strip.text = element_blank())

##### PLOT 4
outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  group_by(outcome_var, covid_first, survey_group) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(survey_group, estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme() +
  ggtitle("MIGRANTS CAN INTEGRATE")


dat_text <- data.frame(
  label = c("COVID-First"),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus4 <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
) 

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out4 <- col_endline %>%
  dplyr::select(!!c(outcomes, controls), covid_first, survey_group) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults4 <- ggplot(reg_out4, aes(x = survey_group, y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Survey Group", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme() +
  theme(strip.text = element_blank())

##### PLOT TOGETHER
(plot_treatmentstatus3 / plot_regresults3 / 
    plot_treatmentstatus4 / plot_regresults4) +
  plot_layout(heights = c(1, 1, 1, 1))

@



\clearpage
\newpage
\section{Heterogeneous Effects}
\label{SIsec:het}

In this section, we explore heterogeneous treatment effects of the COVID-First survey experimental prime by subgroup. For this subgroup analysis, we can only use the cross-sectional sample, because our sample of panelists is too small to conduct subgroup analysis. Here, we combine all cross-sectional respondents.

%\newpage

\subsection{Whether Economically Affected}

Respondents who have experienced employment loss, income loss, or financial stress due to COVID may have \textit{more negative} views.

\subsubsection{Lost Job}

\noindent Of our full sample, there were \Sexpr{table(col_cross$cov_lostjob)[2]} (\Sexpr{(table(col_cross$cov_lostjob)[2]/table(is.na(col_cross$cov_lostjob))[1])*100}\%) respondents who lost their job vs. \Sexpr{table(col_cross$cov_lostjob)[1]} (\Sexpr{(table(col_cross$cov_lostjob)[1]/table(is.na(col_cross$cov_lostjob))[1])*100}\%) who did not.

<<mig_gen_cs_cov_lostjob, eval = FALSE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent lost their job (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  group_by(outcome_var, covid_first, cov_lostjob) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_lostjob), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_lostjob = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_lostjob) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_lostjob), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_cov_lostjob, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent lost their job (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  group_by(outcome_var, covid_first, cov_lostjob) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_lostjob), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_lostjob) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_lostjob), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_cov_lostjob, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent lost their job (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  group_by(outcome_var, covid_first, cov_lostjob) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_lostjob), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  cov_lostjob = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_lostjob) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_lostjob), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_cov_lostjob, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent lost their job (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  group_by(outcome_var, covid_first, cov_lostjob) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_lostjob), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_lostjob = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  dplyr::select(!!c(outcomes, controls), cov_lostjob, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_lostjob) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_lostjob), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_cov_lostjob, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent lost their job (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_lostjob, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(cov_lostjob, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_lostjob)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, cov_lostjob) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_lostjob) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(cov_lostjob), 
                    colour = as.factor(cov_lostjob))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")
@


\subsubsection{Economic Stress}

\noindent Of our full sample, there were \Sexpr{table(col_cross$economic_stress)[2]} (\Sexpr{(table(col_cross$economic_stress)[2]/table(is.na(col_cross$economic_stress))[1])*100}\%) respondents who experienced economic stress (had to use their savings, borrow money, and/or rely on family and friends to make ends meet) vs. \Sexpr{table(col_cross$economic_stress)[1]} (\Sexpr{(table(col_cross$economic_stress)[1]/table(is.na(col_cross$economic_stress))[1])*100}\%) who did not.

<<mig_gen_cs_economic_stress, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent experienced economic stress (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  group_by(outcome_var, covid_first, economic_stress) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(economic_stress), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Economic Stress", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  economic_stress = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, economic_stress) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(economic_stress), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Economic Stress", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_economic_stress, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent experienced economic stress (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  group_by(outcome_var, covid_first, economic_stress) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(economic_stress), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Economic Stress", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, economic_stress) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(economic_stress), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Economic Stress", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_economic_stress, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent experienced economic stress (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  group_by(outcome_var, covid_first, economic_stress) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(economic_stress), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Economic Stress", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  economic_stress = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, economic_stress) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(economic_stress), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Economic Stress", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_economic_stress, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent experienced economic stress (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  group_by(outcome_var, covid_first, economic_stress) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(economic_stress), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Economic Stress", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  economic_stress = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  dplyr::select(!!c(outcomes, controls), economic_stress, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, economic_stress) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(economic_stress), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Economic Stress", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_economic_stress, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent experienced economic stress (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), economic_stress, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(economic_stress, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(economic_stress)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, economic_stress) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, economic_stress) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(economic_stress), 
                    colour = as.factor(economic_stress))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")
@


\subsubsection{Income Loss}

\noindent Of our full sample, there were \Sexpr{table(col_cross$income_loss)[2]} (\Sexpr{(table(col_cross$income_loss)[2]/table(is.na(col_cross$income_loss))[1])*100}\%) respondents who experienced income loss vs. \Sexpr{table(col_cross$income_loss)[1]} (\Sexpr{(table(col_cross$income_loss)[1]/table(is.na(col_cross$income_loss))[1])*100}\%) who did not.


<<mig_gen_cs_income_loss, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent experienced income loss (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  group_by(outcome_var, covid_first, income_loss) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(income_loss), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Income Loss", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  income_loss = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, income_loss) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(income_loss), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Income Loss", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_income_loss, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent experienced income loss (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  group_by(outcome_var, covid_first, income_loss) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(income_loss), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Income Loss", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, income_loss) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(income_loss), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Income Loss", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_income_loss, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent experienced income loss (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  group_by(outcome_var, covid_first, income_loss) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(income_loss), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Income Loss", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  income_loss = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, income_loss) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(income_loss), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Income Loss", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_income_loss, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent experienced income loss (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  group_by(outcome_var, covid_first, income_loss) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(income_loss), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Income Loss", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  income_loss = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  dplyr::select(!!c(outcomes, controls), income_loss, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, income_loss) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(income_loss), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Experienced Income Loss", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_income_loss, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent experienced income loss (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), income_loss, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), income_loss, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), income_loss, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(income_loss, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(income_loss)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, income_loss) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, income_loss) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(income_loss), 
                    colour = as.factor(income_loss))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")
@



\subsection{Whether Health Affected}
\subsubsection{Whether Personal Health Affected}

Respondents whose personal health was been affected by COVID may have \textit{more negative} views. Of the full sample, there were \Sexpr{table(col_cross$cov_self)[2]} (\Sexpr{(table(col_cross$cov_self)[2]/table(is.na(col_cross$cov_self))[1])*100}\%) respondents who got COVID vs. \Sexpr{table(col_cross$cov_self)[1]} (\Sexpr{(table(col_cross$cov_self)[1]/table(is.na(col_cross$cov_self))[1])*100}\%) who did not.

<<mig_gen_cs_cov_self, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent was personally affected by COVID (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  group_by(outcome_var, covid_first, cov_self) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_self), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Personally Affected by COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_self = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_self) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_self), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Personally Affected by COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_cov_self, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent was personally affected by COVID (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  group_by(outcome_var, covid_first, cov_self) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_self), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Personally Affected by COVID", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_self) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_self), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Personally Affected by COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_cov_self, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent was personally affected by COVID (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  group_by(outcome_var, covid_first, cov_self) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_self), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Personally Affected by COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  cov_self = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_self) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_self), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Personally Affected by COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_cov_self, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent was personally affected by COVID (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  group_by(outcome_var, covid_first, cov_self) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_self), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Personally Affected by COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_self = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  dplyr::select(!!c(outcomes, controls), cov_self, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_self) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_self), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Personally Affected by COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_cov_self, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent was personally affected by COVID (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_self, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_self, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_self, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(cov_self, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_self)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, cov_self) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_self) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(cov_self), 
                    colour = as.factor(cov_self))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")
@


\subsubsection{Whether Family Health Affected}

Similarly, respondents whose family's health was been affected by COVID may have \textit{more negative} views. Of the full sample, there were \Sexpr{table(col_cross$cov_family)[2]} (\Sexpr{(table(col_cross$cov_family)[2]/table(is.na(col_cross$cov_family))[1])*100}\%) respondents who had a family member who got COVID vs. \Sexpr{table(col_cross$cov_family)[1]} (\Sexpr{(table(col_cross$cov_family)[1]/table(is.na(col_cross$cov_family))[1])*100}\%) who did not.

<<mig_gen_cs_cov_family, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent's family was affected by COVID (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  group_by(outcome_var, covid_first, cov_family) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_family), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Family Affected by COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_family = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_family) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_family), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Family Affected by COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_cov_family, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent's family was affected by COVID (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  group_by(outcome_var, covid_first, cov_family) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_family), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Family Affected by COVID", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_family) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_family), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Family Affected by COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_cov_family, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent's family was affected by COVID (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  group_by(outcome_var, covid_first, cov_family) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_family), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Family Affected by COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  cov_family = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_family) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_family), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Family Affected by COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_cov_family, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent's family was affected by COVID (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  group_by(outcome_var, covid_first, cov_family) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_family), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Family Affected by COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_family = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  dplyr::select(!!c(outcomes, controls), cov_family, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_family) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_family), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Family Affected by COVID", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_cov_family, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondents' family was affected by COVID (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_family, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_family, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_family, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(cov_family, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_family)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, cov_family) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_family) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(cov_family), 
                    colour = as.factor(cov_family))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")
@




\newpage
\subsection{Whether concerned about Security}

Respondents who are concerned about the security situation due to COVID may have \textit{more negative} views.

\noindent Of our full sample, there were \Sexpr{table(col_cross$cov_concern_three_security)[2]} (\Sexpr{(table(col_cross$cov_concern_three_security)[2]/table(is.na(col_cross$cov_concern_three_security))[1])*100}\%) respondents who reported security as one of their top three concerns vs. \Sexpr{table(col_cross$cov_concern_three_security)[1]} (\Sexpr{(table(col_cross$cov_concern_three_security)[1]/table(is.na(col_cross$cov_concern_three_security))[1])*100}\%) who did not.

<<mig_gen_cs_cov_concern_three_security, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent is concerned about security (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  group_by(outcome_var, covid_first, cov_concern_three_security) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_concern_three_security), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Concerned about Security", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_concern_three_security = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_concern_three_security) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_concern_three_security), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Concerned about Security", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_cov_concern_three_security, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent is concerned about security (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  group_by(outcome_var, covid_first, cov_concern_three_security) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_concern_three_security), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Concerned about Security", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_concern_three_security) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_concern_three_security), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Concerned about Security", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_cov_concern_three_security, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent is concerned about security (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  group_by(outcome_var, covid_first, cov_concern_three_security) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_concern_three_security), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Concerned about Security", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  cov_concern_three_security = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_concern_three_security) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_concern_three_security), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Concerned about Security", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_cov_concern_three_security, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent is concerned about security (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  group_by(outcome_var, covid_first, cov_concern_three_security) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_concern_three_security), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Concerned about Security", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_concern_three_security = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  dplyr::select(!!c(outcomes, controls), cov_concern_three_security, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_concern_three_security) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_concern_three_security), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Concerned about Security", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_cov_concern_three_security, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent is concerned about security (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_concern_three_security, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(cov_concern_three_security, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_concern_three_security)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, cov_concern_three_security) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_concern_three_security) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(cov_concern_three_security), 
                    colour = as.factor(cov_concern_three_security))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")
@


\newpage
\subsection{By City}

Since Cali had smaller concentrations of migrants and more COVID-19 cases, there may be differential reactions by city. The figures below are labeled Cali (1) versus Cúcuta (0). Nevertheless, results show that respondents from either city react similarly; those from Cali are slightly more positive across multiple responses but the differences are not statistically significant.

\noindent Of our full sample, there were \Sexpr{table(col_cross$city_num)[2]} (\Sexpr{(table(col_cross$city_num)[2]/table(is.na(col_cross$city_num))[1])*100}\%) respondents from Cali vs. \Sexpr{table(col_cross$city_num)[1]} (\Sexpr{(table(col_cross$city_num)[1]/table(is.na(col_cross$city_num))[1])*100}\%) from Cúcuta. 

<<mig_gen_cs_city_num, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by Cali (1) vs Cúcuta (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  group_by(outcome_var, covid_first, city_num) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(city_num), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Cali vs. Cúcuta", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_lostjob = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, city_num) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(city_num), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Cali vs. Cúcuta", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_city_num, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by Cali (1) vs Cúcuta (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  group_by(outcome_var, covid_first, city_num) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(city_num), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Cali vs. Cúcuta", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, city_num) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(city_num), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Cali vs. Cúcuta", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_city_num, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by Cali (1) or Cúcuta (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  group_by(outcome_var, covid_first, city_num) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(city_num), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Cali vs. Cúcuta", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  cov_lostjob = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, city_num) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(city_num), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Cali vs. Cúcuta", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_city_num, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by Cali (1) vs. Cúcuta (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  group_by(outcome_var, covid_first, city_num) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(city_num), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Lost Job due to COVID", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  cov_lostjob = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  dplyr::select(!!c(outcomes, controls), city_num, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, city_num) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(city_num), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Cali vs. Cúcuta", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_city_num, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by Cali (1) vs Cúcuta (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), city_num, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), city_num, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), city_num, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(city_num, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(city_num)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, city_num) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, city_num) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(city_num), 
                    colour = as.factor(city_num))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")
@


\newpage
%\subsection{Whether Race is Majority (Mestizo)}

%\noindent Of our full sample, there were \Sexpr{table(col_cross$race_mestizo)[2]} (\Sexpr{(table(col_cross$race_mestizo)[2]/table(is.na(col_cross$race_mestizo))[1])*100}\%) Mestizo respondents vs. \Sexpr{table(col_cross$race_mestizo)[1]} (\Sexpr{(table(col_cross$race_mestizo)[1]/table(is.na(col_cross$race_mestizo))[1])*100}\%) respondents from other races. 

<<mig_gen_cs_race_mestizo, eval = FALSE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent is mestizo (1) or not (0).">>=
    
    outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")
    
    outcomes_names <- c(
        "mig_gen_country" = "Not too many Vens",
        "mig_gen_border" = "Border should be open",
        "mig_gen_city" = "Our city should host Vens",
        "mig_gen_oth_country" = "Right to seek asylum"
    )
    
    ## Controls
    controls <- c("age", 
                  "male",
                  "city_num", 
                  #"race_mestizo", 
                  "education", 
                  "kids", 
                  "marriage", 
                  "religion_cath",
                  "religion_evan",
                  "religiosity", 
                  "wealth_index")
    
    # Create big dataset
    col_endline <- bind_rows(
        col_long %>%
            filter(period == "endline") %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "Panelists (endline)"),
        col_new %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "New Cross-Sectional Respondents",
                   kids = as.numeric(kids)),
        col_cross %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "All Respondents",
                   kids = as.numeric(kids))
    )
    
    ## Estimate over-time means ##
    treatmentstatus_means <- col_endline %>%
        pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        group_by(outcome_var, covid_first, race_mestizo) %>%
        do({
            lm_robust(value~1, data = .) %>% tidy()
        }) %>%
        mutate(est = "Means by Treatment Status")
    
    #plot 
    plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(race_mestizo), estimate, 
                                                              group = as.factor(covid_first), 
                                                              colour = as.factor(covid_first))) + 
        geom_point(position = position_dodge(.4)) + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                      width = 0, position = position_dodge(.4)) +
        facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
        labs(x = "Race = Mestizo", y = "Share of Respondents") + 
        scale_colour_manual(values = c("#0072B2","#D55E00")) + 
        #scale_x_discrete(labels = c("All", "New", "Panel")) +
        yy_theme()
    
    dat_text <- data.frame(
        label = c("Covid-First"),
        cov_lostjob = as.factor(0),
        outcome_var   = c("mig_gen_border"),
        covid_first = c(0,1)
    )
    
    plot_treatmentstatus <- plot_treatmentstatus + geom_text(
        data    = dat_text,
        mapping = aes(x = 1.3, y = .5, label = label)
    )
    
    ## -------------------
    ## Regression analysis
    ## -------------------
    
    control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))
    
    reg_out <- col_endline %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
        pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
        group_by(outcome_var, race_mestizo) %>%
        do({
            lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
                tidy(confint = TRUE) %>%
                filter(term == "covid_first")
        })
    
    
    #plot 
    plot_regresults <- ggplot(reg_out, aes(x = as.factor(race_mestizo), y = estimate)) + 
        geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
        geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
        facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
        labs(x = "Race = Mestizo", 
             y = "Average Treatment Effect") +
        coord_flip() +
        scale_x_discrete(labels = function(x)
            str_wrap(str_replace_all(x, "foo" , " "),
                     width = 15)) +
        yy_theme()
    
    (plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
        plot_regresults
    @
        
<<mig_labor_cs_race_mestizo, eval = FALSE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent is mestizo (1) or not (0).">>=
        
        outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")
    
    outcomes_names <- c(
        "labor_jobs1" = "Vens do not take Cols' jobs",
        "labor_jobs2" = "Vens do not take desirable jobs",
        "labor_compete1" = "I do not compete w/ Vens",
        "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
    )
    
    ## Controls
    controls <- c("age", 
                  "male",
                  "city_num", 
                  #"race_mestizo", 
                  "education", 
                  "kids", 
                  "marriage", 
                  "religion_cath",
                  "religion_evan",
                  "religiosity", 
                  "wealth_index")
    
    # Create big dataset
    col_endline <- bind_rows(
        col_long %>%
            filter(period == "endline") %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "Panelists (endline)"),
        col_new %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "New Cross-Sectional Respondents",
                   kids = as.numeric(kids)),
        col_cross %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "All Respondents",
                   kids = as.numeric(kids))
    )
    
    ## Estimate over-time means ##
    treatmentstatus_means <- col_endline %>%
        pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        group_by(outcome_var, covid_first, race_mestizo) %>%
        do({
            lm_robust(value~1, data = .) %>% tidy()
        }) %>%
        mutate(est = "Means by Treatment Status")
    
    #plot 
    plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(race_mestizo), estimate, 
                                                              group = as.factor(covid_first), 
                                                              colour = as.factor(covid_first))) + 
        geom_point(position = position_dodge(.4)) + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                      width = 0, position = position_dodge(.4)) +
        facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
        labs(x = "Race = Mestizo", y = "Share of Respondents") + 
        #scale_x_discrete(labels = c("All", "New", "Panel")) +
        scale_colour_manual(values = c("#0072B2","#D55E00")) + 
        yy_theme()
    
    dat_text <- data.frame(
        label = c("Covid-First"),
        outcome_var   = c("labor_compete1"),
        covid_first = c(0,1)
    )
    
    plot_treatmentstatus <- plot_treatmentstatus + geom_text(
        data    = dat_text,
        mapping = aes(x = 1.3, y = .5, label = label)
    )
    
    ## -------------------
    ## Regression analysis
    ## -------------------
    
    control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))
    
    reg_out <- col_endline %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
        pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
        group_by(outcome_var, race_mestizo) %>%
        do({
            lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
                tidy(confint = TRUE) %>%
                filter(term == "covid_first")
        })
    
    
    #plot 
    plot_regresults <- ggplot(reg_out, aes(x = as.factor(race_mestizo), y = estimate)) + 
        geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
        geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
        facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
        labs(x = "Race = Mestizo", 
             y = "Average Treatment Effect") +
        coord_flip() +
        scale_x_discrete(labels = function(x)
            str_wrap(str_replace_all(x, "foo" , " "),
                     width = 15)) +
        yy_theme()
    
    (plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
        plot_regresults
    
    
@
        
<<mig_fisc_cs_race_mestizo, eval = FALSE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent is mestizo (1) or not (0)">>=
        
        outcomes <- c("fisc_service", "fisc_aid", 
                      "socio_gen", "sec_conflict")
    
    outcomes_names <- c(
        "fisc_service" = "W/ Vens easier to access services",
        "fisc_aid" = "Enough aid to handle migrants",
        "socio_gen" = "Vens presence benefits Cols",
        "sec_conflict" = "Vens presence mitigates conflict"
    )
    
    ## Controls
    controls <- c("age", 
                  "male",
                  "city_num", 
                  #"race_mestizo", 
                  "education", 
                  "kids", 
                  "marriage", 
                  "religion_cath",
                  "religion_evan",
                  "religiosity", 
                  "wealth_index")
    
    # Create big dataset
    col_endline <- bind_rows(
        col_long %>%
            filter(period == "endline") %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "Panelists (endline)"),
        col_new %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "New Cross-Sectional Respondents",
                   kids = as.numeric(kids)),
        col_cross %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "All Respondents",
                   kids = as.numeric(kids))
    )
    
    ## Estimate over-time means ##
    treatmentstatus_means <- col_endline %>%
        pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        group_by(outcome_var, covid_first, race_mestizo) %>%
        do({
            lm_robust(value~1, data = .) %>% tidy()
        }) %>%
        mutate(est = "Means by Treatment Status")
    
    #plot 
    plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(race_mestizo), estimate, 
                                                              group = as.factor(covid_first), 
                                                              colour = as.factor(covid_first))) + 
        geom_point(position = position_dodge(.4)) + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                      width = 0, position = position_dodge(.4)) +
        facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
        labs(x = "Race = Mestizo", y = "Share of Respondents") + 
        scale_colour_manual(values = c("#0072B2","#D55E00")) + 
        #scale_x_discrete(labels = c("All", "New", "Panel")) +
        yy_theme()
    
    
    dat_text <- data.frame(
        label = c("Covid-First"),
        race_mestizo = as.factor(0),
        outcome_var   = c("fisc_aid"),
        covid_first = c(0,1)
    )
    
    plot_treatmentstatus <- plot_treatmentstatus + geom_text(
        data    = dat_text,
        mapping = aes(x = 1.3, y = .5, label = label)
    )
    
    ## -------------------
    ## Regression analysis
    ## -------------------
    
    control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))
    
    reg_out <- col_endline %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
        pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
        group_by(outcome_var, race_mestizo) %>%
        do({
            lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
                tidy(confint = TRUE) %>%
                filter(term == "covid_first")
        })
    
    #plot 
    plot_regresults <- ggplot(reg_out, aes(x = as.factor(race_mestizo), y = estimate)) + 
        geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
        geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
        facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
        labs(x = "Race = Mestizo", 
             y = "Average Treatment Effect") +
        coord_flip() +
        scale_x_discrete(labels = function(x)
            str_wrap(str_replace_all(x, "foo" , " "),
                     width = 15)) +
        yy_theme()
    
    (plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
        plot_regresults
    
@
        
<<mig_soc_cs_race_mestizo, eval = FALSE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent is mestizo (1) or not (0)">>=
        
        outcomes <- c("socio_work", "socio_integrate", 
                      "pol_left", "hist_culture")
    
    outcomes_names <- c(
        "socio_work" = "Vens are hardworking",
        "socio_integrate" = "Vens integrate successfully",
        "pol_left" = "Vens are leftist",
        "hist_culture" = "Cols and Vens share cultural ties"
    )
    
    ## Controls
    controls <- c("age", 
                  "male",
                  "city_num", 
                  #"race_mestizo", 
                  "education", 
                  "kids", 
                  "marriage", 
                  "religion_cath",
                  "religion_evan",
                  "religiosity", 
                  "wealth_index")
    
    # Create big dataset
    col_endline <- bind_rows(
        col_long %>%
            filter(period == "endline") %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "Panelists (endline)"),
        col_new %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "New Cross-Sectional Respondents",
                   kids = as.numeric(kids)),
        col_cross %>%
            dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "All Respondents",
                   kids = as.numeric(kids))
    )
    
    ## Estimate over-time means ##
    treatmentstatus_means <- col_endline %>%
        pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        group_by(outcome_var, covid_first, race_mestizo) %>%
        do({
            lm_robust(value~1, data = .) %>% tidy()
        }) %>%
        mutate(est = "Means by Treatment Status")
    
    #plot 
    plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(race_mestizo), estimate, 
                                                              group = as.factor(covid_first), 
                                                              colour = as.factor(covid_first))) + 
        geom_point(position = position_dodge(.4)) + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                      width = 0, position = position_dodge(.4)) +
        facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
        labs(x = "Race = Mestizo", y = "Share of Respondents") + 
        scale_colour_manual(values = c("#0072B2","#D55E00")) + 
        #scale_x_discrete(labels = c("All", "New", "Panel")) +
        yy_theme()
    
    dat_text <- data.frame(
        label = c("Covid-First"),
        cov_lostjob = as.factor(0),
        outcome_var   = c("hist_culture"),
        covid_first = c(0,1)
    )
    
    plot_treatmentstatus <- plot_treatmentstatus + geom_text(
        data    = dat_text,
        mapping = aes(x = 1.3, y = .5, label = label)
    )
    
    ## -------------------
    ## Regression analysis
    ## -------------------
    
    control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))
    
    reg_out <- col_endline %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        dplyr::select(!!c(outcomes, controls), race_mestizo, covid_first) %>%
        pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
        group_by(outcome_var, race_mestizo) %>%
        do({
            lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
                tidy(confint = TRUE) %>%
                filter(term == "covid_first")
        })
    
    
    #plot 
    plot_regresults <- ggplot(reg_out, aes(x = as.factor(race_mestizo), y = estimate)) + 
        geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
        geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
        facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
        labs(x = "Race = Mestizo", 
             y = "Average Treatment Effect") +
        coord_flip() +
        scale_x_discrete(labels = function(x)
            str_wrap(str_replace_all(x, "foo" , " "),
                     width = 15)) +
        yy_theme()
    
    (plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
        plot_regresults
    
@
        
<<mig_cov_results_race_mestizo, eval = FALSE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent is mestizo (1) or not (0).">>=
        
        outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                         "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")
    
    outcomes_cs_names <- c(
        "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
        "mig_cov_resource" = "Vens not using\nup health resources",
        "mig_cov_assist" = "Vens not getting\nmore assistance",
        "mig_cov_essw" = "Vens are\nessential workers",
        "mig_cov_border" = "Open border\nduring COVID",
        "mig_cov_return" = "Vens should\nremain in Col",
        "mig_cov_reg" = "Vens obey\nprotocols",
        "sympathy" = "Vens deserve\nsympathy"
    )
    
    controls <- c("age", "male", "city_num", 
                  #"race_mestizo", 
                  "education", "kids", "marriage", 
                  "religion_cath","religion_evan","religiosity", "wealth_index")
    
    ## Create big dataset
    col_endline <- bind_rows(
        col_long %>%
            filter(period == "endline") %>%
            dplyr::select(!!c(outcomes_cs, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "Panelists (endline)"),
        col_new %>%
            dplyr::select(!!c(outcomes_cs, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "New Cross-Sectional Respondents",
                   kids = as.numeric(kids)),
        col_cross %>%
            dplyr::select(!!c(outcomes_cs, controls), race_mestizo, covid_first) %>%
            mutate(survey_group = "All Respondents",
                   kids = as.numeric(kids))
    )
    
    ## Means
    means <- col_endline %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
        group_by(race_mestizo, outcome_var) %>%
        do({
            lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
        })
    
    ## Treatment effects
    control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))
    
    treatment_effects <- col_endline %>%
        filter(survey_group == "All Respondents" & !is.na(race_mestizo)) %>%
        dplyr::select(!!c(outcomes_cs, controls), covid_first, race_mestizo) %>%
        pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
        group_by(outcome_var, race_mestizo) %>%
        do({
            lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
                tidy(confint = TRUE) %>%
                filter(term == "covid_first")
        })
    
    ## Plot
    df_plot <- bind_rows(
        means %>% mutate(est_type = "Proportion of Respondents"),
        treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
    )
    
    pd <- position_dodge(.8)
    
    ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(race_mestizo), 
                        colour = as.factor(race_mestizo))) + 
        geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
                   aes(yintercept = y), lty = "dashed", color = "gray60") + 
        geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
        geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
        scale_x_discrete(labels=outcomes_cs_names) + 
        facet_wrap(~est_type, scales = "free_y", nrow = 2) +
        scale_colour_manual(values = c("#0072B2","#D55E00")) + 
        yy_theme() +
        theme(axis.title.x=element_blank(),
              axis.title.y=element_blank(),
              axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
              legend.position="bottom")
@


\newpage
\subsection{Whether Have Contact with Venezuelans}

Respondents who have more contact with Venezuelan migrants may have \textit{more positive} views.

\noindent Of our full sample, there were \Sexpr{table(col_cross$ven_friends_bi)[2]} (\Sexpr{(table(col_cross$ven_friends_bi)[2]/table(is.na(col_cross$ven_friends_bi))[1])*100}\%) respondents who have Venezuelan friends vs. \Sexpr{table(col_cross$ven_friends_bi)[1]} (\Sexpr{(table(col_cross$ven_friends_bi)[1]/table(is.na(col_cross$ven_friends_bi))[1])*100}\%) who do not.

<<mig_gen_cs_ven_friends_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent has at least one Venezuelan friend (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  group_by(outcome_var, covid_first, ven_friends_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(ven_friends_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Has At Least One Venezuelan Friend", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  ven_friends_bi = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, ven_friends_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(ven_friends_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Has At Least One Venezuelan Friend", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_ven_friends_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent has at least one Venezuelan friend (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  group_by(outcome_var, covid_first, ven_friends_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(ven_friends_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Has At Least One Venezuelan Friend", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, ven_friends_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(ven_friends_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Has At Least One Venezuelan Friend", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_ven_friends_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent has at least one Venezuelan friend (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  group_by(outcome_var, covid_first, ven_friends_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(ven_friends_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Has At Least One Venezuelan Friend", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  ven_friends_bi = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, ven_friends_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(ven_friends_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Has At Least One Venezuelan Friend", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_ven_friends_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent has at least one Venezuelan friend (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  group_by(outcome_var, covid_first, ven_friends_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(ven_friends_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Has At Least One Venezuelan Friend", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  ven_friends_bi = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  dplyr::select(!!c(outcomes, controls), ven_friends_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, ven_friends_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(ven_friends_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Has At Least One Venezuelan Friend", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_ven_friends_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent has at least one Venezuelan friend (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", "mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), ven_friends_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(ven_friends_bi, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(ven_friends_bi)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, ven_friends_bi) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, ven_friends_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(ven_friends_bi), 
                    colour = as.factor(ven_friends_bi))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")
@


\newpage
\subsection{Whether Have Belief that Migrants are Essential Workers}

Respondents who view Venezuelan migrants as essential workers may have \textit{more positive} views.\\

\noindent Of our full sample, there were \Sexpr{table(col_cross$mig_cov_essw)[2]} (\Sexpr{(table(col_cross$mig_cov_essw)[2]/table(is.na(col_cross$mig_cov_essw))[1])*100}\%) respondents who view Venezuelan migrants as essential workers vs. \Sexpr{table(col_cross$mig_cov_essw)[1]} (\Sexpr{(table(col_cross$mig_cov_essw)[1]/table(is.na(col_cross$mig_cov_essw))[1])*100}\%) who do not.

<<mig_gen_cs_mig_cov_essw, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent thinks migrants are essential workers (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  group_by(outcome_var, covid_first, mig_cov_essw) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(mig_cov_essw), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Migrants are Essential Workers", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, mig_cov_essw) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(mig_cov_essw), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Migrants are Essential Workers", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_mig_cov_essw, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent thinks migrants are essential workers (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  group_by(outcome_var, covid_first, mig_cov_essw) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(mig_cov_essw), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Migrants are Essential Workers", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, mig_cov_essw) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(mig_cov_essw), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Migrants are Essential Workers", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_mig_cov_essw, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent thinks migrants are essential workers (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  group_by(outcome_var, covid_first, mig_cov_essw) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(mig_cov_essw), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Migrants are Essential Workers", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, mig_cov_essw) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(mig_cov_essw), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Migrants are Essential Workers", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_mig_cov_essw, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent thinks migrants are essential workers (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  group_by(outcome_var, covid_first, mig_cov_essw) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(mig_cov_essw), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Migrants are Essential Workers", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  dplyr::select(!!c(outcomes, controls), mig_cov_essw, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, mig_cov_essw) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(mig_cov_essw), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Migrants are Essential Workers", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_mig_cov_essw, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent thinks migrants are essential workers (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", #"mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    #"mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), mig_cov_essw, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(mig_cov_essw, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(mig_cov_essw)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, mig_cov_essw) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, mig_cov_essw) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(mig_cov_essw), 
                    colour = as.factor(mig_cov_essw))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")

@


\newpage
\subsection{Whether Have Belief that Government Response to COVID was Not Sufficient or (More than) Appropriate}

Respondents who view the government response, national or local, as sufficient may have \textit{more positive} views.\\

\subsubsection{National Response}

\noindent Of our full sample, there were \Sexpr{table(col_cross$cov_natgov_bi)[2]} (\Sexpr{(table(col_cross$cov_natgov_bi)[2]/table(is.na(col_cross$cov_natgov_bi))[1])*100}\%) respondents who thought the national government response was sufficient or more than sufficient vs. \Sexpr{table(col_cross$cov_natgov_bi)[1]} (\Sexpr{(table(col_cross$cov_natgov_bi)[1]/table(is.na(col_cross$cov_natgov_bi))[1])*100}\%) who thought it was inadequate. 

<<mig_gen_cs_cov_natgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent thinks the national government response was sufficient (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  group_by(outcome_var, covid_first, cov_natgov_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_natgov_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think National Response was Sufficient", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_natgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_natgov_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think National Response was Sufficient", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_cov_natgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent thinks the national government response was sufficient (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  group_by(outcome_var, covid_first, cov_natgov_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_natgov_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think National Response was Sufficient", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_natgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_natgov_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think National Response was Sufficient", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_cov_natgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent thinks the national government response was sufficient (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  group_by(outcome_var, covid_first, cov_natgov_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_natgov_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think National Response was Sufficient", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_natgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_natgov_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think National Response was Sufficient", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_cov_natgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent thinks the national government response was sufficient (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  group_by(outcome_var, covid_first, cov_natgov_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_natgov_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think National Response was Sufficient", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  dplyr::select(!!c(outcomes, controls), cov_natgov_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_natgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_natgov_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think National Response was Sufficient", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_cov_natgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent thinks the national government response was sufficient (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", #"mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_natgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(cov_natgov_bi, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_natgov_bi)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, cov_natgov_bi) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_natgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(cov_natgov_bi), 
                    colour = as.factor(cov_natgov_bi))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")

@


\subsubsection{Local Response}

\noindent Of our full sample, there were \Sexpr{table(col_cross$cov_locgov_bi)[2]} (\Sexpr{(table(col_cross$cov_locgov_bi)[2]/table(is.na(col_cross$cov_locgov_bi))[1])*100}\%) respondents who thought the national government response was sufficient or more than sufficient vs. \Sexpr{table(col_cross$cov_locgov_bi)[1]} (\Sexpr{(table(col_cross$cov_locgov_bi)[1]/table(is.na(col_cross$cov_locgov_bi))[1])*100}\%) who thought it was inadequate. 

<<mig_gen_cs_cov_locgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Migration Openness Outcomes, by whether the respondent thinks the local government response was sufficient (1) or not (0).">>=

outcomes <- c("mig_gen_country", "mig_gen_border", "mig_gen_city", "mig_gen_oth_country")

outcomes_names <- c(
                    "mig_gen_country" = "Not too many Vens",
                    "mig_gen_border" = "Border should be open",
                    "mig_gen_city" = "Our city should host Vens",
                    "mig_gen_oth_country" = "Right to seek asylum"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  group_by(outcome_var, covid_first, cov_locgov_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_locgov_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Local Response was Sufficient", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("mig_gen_border"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_locgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_locgov_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Local Response was Sufficient", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRATION OPENNESS ATTITUDES")) /
  plot_regresults
@

<<mig_labor_cs_cov_locgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Compete for Jobs, by whether the respondent thinks the local government response was sufficient (1) or not (0).">>=

outcomes <- c("labor_jobs1", "labor_jobs2", "labor_compete1", "labor_compete2")

outcomes_names <- c(
                    "labor_jobs1" = "Vens do not take Cols' jobs",
                    "labor_jobs2" = "Vens do not take desirable jobs",
                    "labor_compete1" = "I do not compete w/ Vens",
                    "labor_compete2" = "Cols in my city\ndo not compete w/ Vens"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!outcomes, names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  group_by(outcome_var, covid_first, cov_locgov_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_locgov_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Local Response was Sufficient", y = "Share of Respondents") + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  outcome_var   = c("labor_compete1"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_locgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_locgov_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Local Response was Sufficient", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS COMPETE FOR EMPLOYMENT")) /
  plot_regresults


@

<<mig_fisc_cs_cov_locgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Bring Benefits, by whether the respondent thinks the local government response was sufficient (1) or not (0).">>=

outcomes <- c("fisc_service", "fisc_aid", 
              "socio_gen", "sec_conflict")

outcomes_names <- c(
                    "fisc_service" = "W/ Vens easier to access services",
                    "fisc_aid" = "Enough aid to handle migrants",
                    "socio_gen" = "Vens presence benefits Cols",
                    "sec_conflict" = "Vens presence mitigates conflict"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  group_by(outcome_var, covid_first, cov_locgov_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_locgov_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Local Response was Sufficient", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()


dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("fisc_aid"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_locgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_locgov_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Local Response was Sufficient", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_soc_cs_cov_locgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Whether Migrants Can Integrate, by whether the respondent thinks the local government response was sufficient (1) or not (0).">>=

outcomes <- c("socio_work", "socio_integrate", 
              "pol_left", "hist_culture")

outcomes_names <- c(
                    "socio_work" = "Vens are hardworking",
                    "socio_integrate" = "Vens integrate successfully",
                    "pol_left" = "Vens are leftist",
                    "hist_culture" = "Cols and Vens share cultural ties"
                    )

## Controls
controls <- c("age", 
              "male",
              "city_num", 
              "race_mestizo", 
              "education", 
              "kids", 
              "marriage", 
              "religion_cath",
              "religion_evan",
              "religiosity", 
              "wealth_index")

# Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Estimate over-time means ##
treatmentstatus_means <- col_endline %>%
  pivot_longer(!!c(outcomes), names_to = "outcome_var", values_to = "value") %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  group_by(outcome_var, covid_first, cov_locgov_bi) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy()
  }) %>%
  mutate(est = "Means by Treatment Status")

#plot 
plot_treatmentstatus <- ggplot(treatmentstatus_means, aes(as.factor(cov_locgov_bi), estimate, 
                                              group = as.factor(covid_first), 
                         colour = as.factor(covid_first))) + 
  geom_point(position = position_dodge(.4)) + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), 
                width = 0, position = position_dodge(.4)) +
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Local Response was Sufficient", y = "Share of Respondents") + 
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  #scale_x_discrete(labels = c("All", "New", "Panel")) +
  yy_theme()

dat_text <- data.frame(
  label = c("Covid-First"),
  mig_cov_essw = as.factor(0),
  outcome_var   = c("hist_culture"),
  covid_first = c(0,1)
)

plot_treatmentstatus <- plot_treatmentstatus + geom_text(
  data    = dat_text,
  mapping = aes(x = 1.3, y = .5, label = label)
)

## -------------------
## Regression analysis
## -------------------

control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

reg_out <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  dplyr::select(!!c(outcomes, controls), cov_locgov_bi, covid_first) %>%
  pivot_longer(cols = !!outcomes, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_locgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })
  

#plot 
plot_regresults <- ggplot(reg_out, aes(x = as.factor(cov_locgov_bi), y = estimate)) + 
  geom_hline(aes(yintercept = 0), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5) + 
  facet_wrap(~outcome_var, labeller = as_labeller(outcomes_names), nrow = 1) +
  labs(x = "Think Local Response was Sufficient", 
       y = "Average Treatment Effect") +
  coord_flip() +
  scale_x_discrete(labels = function(x)
    str_wrap(str_replace_all(x, "foo" , " "),
             width = 15)) +
  yy_theme()

(plot_treatmentstatus + ggtitle("MIGRANTS BRING BENEFITS")) /
  plot_regresults

@

<<mig_cov_results_cov_locgov_bi, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 8, fig.height = 5, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="COVID Endline-only Attitudes, by whether the respondent thinks the local government response was sufficient (1) or not (0).">>=

outcomes_cs <- c("mig_cov_vector", "mig_cov_resource", "mig_cov_assist", #"mig_cov_essw", 
                 "mig_cov_border", "mig_cov_return", "mig_cov_reg", "sympathy")

outcomes_cs_names <- c(
                    "mig_cov_vector" = "Vens no more\nlikely to spread COVID",
                    "mig_cov_resource" = "Vens not using\nup health resources",
                    "mig_cov_assist" = "Vens not getting\nmore assistance",
                    "mig_cov_essw" = "Vens are\nessential workers",
                    "mig_cov_border" = "Open border\nduring COVID",
                    "mig_cov_return" = "Vens should\nremain in Col",
                    "mig_cov_reg" = "Vens obey\nprotocols",
                    "sympathy" = "Vens deserve\nsympathy"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), cov_locgov_bi, covid_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(cov_locgov_bi, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  filter(survey_group == "All Respondents" & !is.na(cov_locgov_bi)) %>%
  dplyr::select(!!c(outcomes_cs, controls), covid_first, cov_locgov_bi) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, cov_locgov_bi) %>%
  do({
    lm_lin(value~covid_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "covid_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of COVID-First")
)

pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = as.factor(cov_locgov_bi), 
                    colour = as.factor(cov_locgov_bi))) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of COVID-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#0072B2","#D55E00")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")

@


\newpage
\section{Treatment Effect of Migration Module First}
\label{SIsec:migfirst}

This section shows the effects of receiving Migration-First Question Module on the COVID questions that ask about government assessment (i.e. the COVID questions that do not ask for factual information). These questions about the COVID response were asked only at endline. They are all on a five point scale. The top plot shows the proportion of our panel (black), new (orange), and all (blue) cross-sectional respondents. The bottom plot shows the effect of receiving the Migration block first, controlling for demographic covariates. 

<<cov_respose_results, eval = TRUE, echo = FALSE, tidy=TRUE, fig.width = 10, fig.height = 5, out.width= "1\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="Effects of Migration-First Question Module on the COVID questions.">>=


outcomes_cs <- c("cov_natgov", "cov_truthgov", "cov_locgov", "cov_public")

outcomes_cs_names <- c(
                    "cov_natgov" = "National govt's COVID-19\nresponse too extreme",
                    "cov_truthgov" = "National govt's COVID-19\nresponse very honest",
                    "cov_locgov" = "Local govt's COVID-19\nresponse too extreme",
                    "cov_public" = "Public's COVID-19\nresponse much too seriously"
                    )

controls <- c("age", "male", "city_num", 
              "race_mestizo", "education", "kids", "marriage", 
              "religion_cath","religion_evan","religiosity", "wealth_index")

## Create big dataset
col_endline <- bind_rows(
  col_long %>%
    filter(period == "endline") %>%
    dplyr::select(!!c(outcomes_cs, controls), migQ_first) %>%
    mutate(survey_group = "Panelists (endline)"),
  col_new %>%
    dplyr::select(!!c(outcomes_cs, controls), migQ_first) %>%
    mutate(survey_group = "New Cross-Sectional Respondents",
           kids = as.numeric(kids)),
  col_cross %>%
    dplyr::select(!!c(outcomes_cs, controls), migQ_first) %>%
    mutate(survey_group = "All Respondents",
           kids = as.numeric(kids))
)

## Means
means <- col_endline %>%
  dplyr::select(survey_group, !!outcomes_cs) %>%
  pivot_longer(cols = -survey_group, names_to = "outcome_var") %>%
  group_by(survey_group, outcome_var) %>%
  do({
    lm_robust(value~1, data = .) %>% tidy(confint = TRUE)
  })

## Treatment effects
control_formula <- as.formula(paste0("~", paste0(controls, collapse = "+")))

treatment_effects <- col_endline %>%
  dplyr::select(!!c(outcomes_cs, controls), migQ_first, survey_group) %>%
  pivot_longer(cols = !!outcomes_cs, names_to = "outcome_var") %>%
  group_by(outcome_var, survey_group) %>%
  do({
    lm_lin(value~migQ_first, covariates = control_formula, data = .) %>% 
      tidy(confint = TRUE) %>%
      filter(term == "migQ_first")
  })

## Plot
df_plot <- bind_rows(
  means %>% mutate(est_type = "Proportion of Respondents"),
  treatment_effects %>% mutate(est_type = "Treatment Effect of MigQ-First")
) %>%
  mutate(survey_group = as.factor(survey_group),
         survey_group = fct_relevel(survey_group, "New Respondents", "Panel Respondents", "All Respondents"))


pd <- position_dodge(.8)

ggplot(df_plot, aes(outcome_var, estimate, group = survey_group, colour = survey_group)) + 
  geom_hline(data = data.frame(est_type = "Treatment Effect of MigQ-First", y = 0), 
             aes(yintercept = y), lty = "dashed", color = "gray60") + 
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .15, position = pd) + 
  geom_label(aes(label = gsub("0\\.", "\\.", round(estimate, 3))), size = 2.5, position = pd) + 
  scale_x_discrete(labels=outcomes_cs_names) + 
  facet_wrap(~est_type, scales = "free_y", nrow = 2) +
  scale_colour_manual(values = c("#D55E00", "black", "#0072B2"), name = "Group", labels = c("New", "Panel", "All")) + 
  yy_theme() +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.x = element_text(angle=0, vjust=0, hjust = .4, size=9),
        legend.position="bottom")

@


\clearpage
\newpage
\section{Multiple Hypothesis Testing Corrections}
\label{SIsec:multhypothesis}

Although most of our findings show null results, because we examine so many outcomes, we adjust for the false discovery rate (FDR) in this section. We show the Benjamini-Hochberg (BH) adjusted p-values for each test of our results in the paper. We show the adjusted p-values within the analysis in our main results shown in the paper. 
%Our statistically significant findings hold.

<<multiple_hypothesis_correction, eval = TRUE, echo = FALSE, tidy=TRUE, results = "asis", warning=FALSE, message=FALSE>>=

# Figure 3
fig3_mh <- bind_rows(
  covid_did_out1,
  covid_did_out2,
  covid_did_out3,
  covid_did_out4
) %>% dplyr::select(term, outcome, estimate, std.error, p.value) %>%
  group_by(term) %>%
  mutate(p.value.adj = p.adjust(p.value, "BH")) %>%
  arrange(term) %>%
  rename(Effect = term, Outcome = outcome, Estimate = estimate, SE = std.error, `P-Value (Unadjusted)` = p.value,
         `P-Value (BH-Adjusted within Effect)` = p.value.adj)

# Figure 4
fig4_mh <- bind_rows(
  reg_out1,
  reg_out2,
  reg_out3,
  reg_out4
) %>% dplyr::select(survey_group, outcome_var, estimate, std.error, p.value) %>%
  group_by(survey_group) %>%
  mutate(p.value.adj = p.adjust(p.value, "BH")) %>%
  arrange(survey_group) %>%
  rename(`Survey Group` = survey_group, Outcome = outcome_var, Estimate = estimate, SE = std.error, `P-Value (Unadjusted)` = p.value,
         `P-Value (BH-Adjusted within Survey Group)` = p.value.adj)

# Figure 5
fig5_mh <- treatment_effects %>%
  dplyr::select(survey_group, outcome_var, estimate, std.error, p.value) %>%
  group_by(survey_group) %>%
  mutate(p.value.adj = p.adjust(p.value, "BH")) %>%
  arrange(survey_group) %>%
  rename(`Survey Group` = survey_group, Outcome = outcome_var, Estimate = estimate, SE = std.error, `P-Value (Unadjusted)` = p.value,
         `P-Value (BH-Adjusted within Survey Group)` = p.value.adj)

# show tables
library(kableExtra)

knitr::kable(fig3_mh,
  col.names = c("Effect", "Outcome", "Estimate", "SE", "Unadj. P-value", "Adj. P-value"),
  digits = c(2,2,2,2,2,2),
  caption = "Benjamini-Hochberg (BH) adjusted p-values for the Diff-in-Diff estimates shown in Figure 3"
  )  %>%
  kable_styling(font_size = 7, latex_options = "HOLD_position")

knitr::kable(fig4_mh,
  col.names = c("Effect", "Outcome", "Estimate", "SE", "Unadj. P-value", "Adj. P-value"),
  digits = c(2,2,2,2,2,2),
  caption = "Benjamini-Hochberg (BH) adjusted p-values for the Cross-sectional estimates shown in Figure 4"
  )  %>%
  kable_styling(font_size = 7, latex_options = "HOLD_position")

knitr::kable(fig5_mh,
  col.names = c("Effect", "Outcome", "Estimate", "SE", "Unadj. P-value", "Adj. P-value"),
  digits = c(2,2,2,2,2,2),
  caption = "Benjamini-Hochberg (BH) adjusted p-values for the Endline Only estimates shown in Figure 5"
  ) %>% 
  kable_styling(latex_options="scale_down")

@


\clearpage
\newpage
\section{Text Analysis}
\label{SIsec:text_analysis}

In this section, we present results from a text analysis that provides suggestive observational evidence on the evolution of media coverage on news related to Venezuelan migrants and the pandemic in Colombia. We used the Factiva database to collect newspaper reports published between 2020-10-01 and 2021-10-01 in Colombia and conduct the sentiment analysis. We scrapped reports where text included the following words given the specified logic: (venezolanos \emph{and} migrantes) \emph{and} (covid \emph{or} pandemia \emph{or} coronavirus). All news reports are in Spanish. After scrapping them, we built a corpus (collection of texts) to run the sentiment analysis.

<<text_analysis, eval = TRUE, echo = FALSE, tidy=TRUE, fig.pos = 'H', fig.width = 7, fig.height = 4, out.width= ".9\\linewidth", fig.align='center', warning=FALSE, message=FALSE, strip.white=TRUE, fig.cap="This figure shows the positive (higher values) versus negative (lower values) coverage of news related to Venezuelan migrants and the pandemic in Colombia.">>=


knitr::include_graphics("Paper_Inputs/news_border_positive.jpg")


@

We used the R package \texttt{Quanteda} to conduct the sentiment analysis. After cleaning and tokenizing the corpus, we specified a 5-word window around the pattern \emph{migrant*} and applied a dictionary of sentiments to the specified context. We employed the emotion lexicon developed by the National Research Council of Canada (NRC). This sentiment dictionary is widely used in text analysis and includes a version in Spanish. Applying the dictionary to the specified context allowed us to detect the occurrences of words that transmit a particular sentiment. For example, if one of the five words following the term \emph{migrant*} is  `good’ and the remaining four words are `neutral’, the positive sentiment in this context will be 1. Put another way, a positive sentiment score is the number of words classified as positive by the NRC sentiment dictionary. Of note is that a high positive sentiment on a particular day can occur because a news report used several positive words or because many news reports used some positive words. We standardized the positive sentiment score to have a mean of 0 and a standard deviation of 1, where high numbers indicate more positive sentiment. Figure \ref{fig:text_analysis} shows that after the borders reopened in March 2021, positive sentiment in the media about migrants increased, but then positive sentiments declined again by fall later that year. 



\clearpage
\newpage
\section{Questionnaire Text (English Version)}
\label{SIsec:survey}

\includepdf[pages=-]{COVID_Colombian Survey_English_Dec10.pdf}





%%%%%% REFERENCES %%%%%%%
\newpage
\setstretch{1}
\bibliography{colombiacovid}

\end{document}

